function getScrollTop(){
    if(typeof pageYOffset!= 'undefined'){
        //most browsers
        return pageYOffset;
    }
    else{
        var B= document.body; //IE 'quirks'
        var D= document.documentElement; //IE with doctype
        D= (D.clientHeight)? D: B;
        return D.scrollTop;
    }
}

jQuery(
    function(){

        var nImgs = jQuery('#fasciaflash img.fade').length;
        var ft = false;

        var speed = 500;
        var duration = 4000;

        function fade(i){
            jQuery('#fasciaflash img.fade:eq('+(((i+nImgs)-1)%nImgs)+')').fadeOut(speed);
            jQuery('#fasciaflash img.fade:eq('+i+')').fadeIn(speed);
            ft = window.setTimeout(
                function(){
                    fade((i+1)%nImgs);
                },duration
            );
        }

        fade(0);

//        jQuery('#fasciaflash img.fade').load(
//            function(){
//
//                if(jQuery(this).index()==(nImgs-1)){
//                    fade(0);
//                }
//
//            }
//        );


	jQuery('#widget').bind({
        mouseenter: function(){
            if(!jQuery('#boxIscrizione').hasClass('active')){
                jQuery(this).stop(false,true).animate({
                    paddingLeft:'+=10px'
                }, 200
                );
            }
        },
        click: function(){
            if(!jQuery('#boxIscrizione').hasClass('active')){
                jQuery('#boxIscrizione').fadeIn(500);
                jQuery('#boxIscrizione').addClass('active');
            }
            else{
                jQuery('#boxIscrizione').removeClass('active');
                jQuery('#boxIscrizione').fadeOut(500);
            }
            
        },
        mouseleave: function(){
            if(!jQuery('#boxIscrizione').hasClass('active')){
                jQuery(this).stop(false,true).animate({
                    paddingLeft:'-=10px'
                }, 200
                );
            }
        }
    });

        jQuery('#homeNews').each(
            function(){

                var cur = 0;
                var size = jQuery('.news',jQuery(this)).length;
                var i = false;
                var isscrolling = false;
                function scroll(i){
                    jQuery('#homeNews .newsWr').scrollTo(jQuery('#homeNews .news:eq('+i+')'),500);
                }

                function init(){
                    isscrolling = true;
                    i = window.setInterval(
                        function(){

                            cur = (cur+1)%size;
                            scroll(cur);
                        },5000
                    );
                }

                function stop(){
                    isscrolling = false;
                    window.clearInterval(i);
                }

                init();

                jQuery('.news',jQuery(this)).hover(
                    function(){
                        if(isscrolling){
                            stop();
                        }
                    },
                    function(){
                        if(!isscrolling){
                            init();
                        }
                    }
                );

            }
        );

//        jQuery('.homeBox').each(
//            function(){
//                var op = 0;
//                var ot = jQuery(this).css('top');
//                var or = jQuery(this).css('right');
//                var ow = jQuery(this).css('width');
//                var oh = jQuery(this).css('height');
//                var speed = 50;
//                //#B13636
//
//                jQuery(this).hover(
//                    function(){
//
//                        jQuery(this).stop(false,true).animate(
//                            {
//                                padding: '3px',
//                                top: '-=3px',
//                                right: '-=3px'
//                            },speed
//                        );
//
//                    },
//                    function(){
//
//                        jQuery(this).stop(false,true).animate(
//                            {
//                                padding: op,
//                                top: ot,
//                                right: or
//                            },speed
//                        );
//
//                    }
//                );
//            }
//       );

    }
);

