// JavaScript Document

 	var times = 5;
    var quant = 2;
    var quant2 = 2;
    var quant3 = 2;
    var timetogo = 2;
    var timetoleave = 1;
    var executing = 0;
    var onmoving = 0;
    
    
    
    function takeLeft( direction )
    {
        onmoving =1;
        $('#bgcarousel ul').animate(
            { left: ( -parseInt((968) * direction ) ) },
            1200,'swing',
            function(){
                if( direction == parseInt(times+1) )
                {
                    
                    $('#bgcarousel ul').css({left: -968});
                    quant=2;
                }
                onmoving = 0;
            }
        );
        quant = direction+1;
    }
    function takeLeft2( direction2 )
    {
        onmoving =1;
        $('#visualcarousel ul').animate(
            { left: ( -parseInt((968)*direction2) ) },
            1200,'swing',
            function(){
                if( direction2 == parseInt(times+1) )
                {
                    $('#visualcarousel ul').css({left: -968});
                    quant2=2;
                }
                onmoving = 0;
            }
        );
        quant2 = direction2+1;
    }
    
    
    
    function fadeTime(leave,togo)
    {
        //console.log( 'fadeTime = timetogo: '+togo+' timetoleave: '+leave );
        /*$('#visualcontroller .time'+leave+' a').fadeTo(300,0, function () {
            
            $('#visualcontroller .time'+leave+' a').removeClass("active").addClass("noactive");
            $('#visualcontroller .time'+parseInt(leave)+' a span').removeShadow();
            if( $.browser.msie )
            {
                $('#visualcontroller .time'+parseInt(leave)+' a span').css({
                        'background' : 'none'
                        //'filter' : 'Shadow(Color=#222222, Direction=-180, Strength=1.5)'
                        
                    });
            }
            else{
                $('#visualcontroller .time'+parseInt(leave)+' a span').dropShadow({left: 0, top: 1, blur: 0, opacity : 0.7, color: "#000000", swap: false});
            }
            
            
            $('#visualcontroller .time'+leave+' a').fadeTo(300,1, function () {
                
            });
            //console.log(qr);
            //qr = parseInt(qr) >= 5 ? 6 : parseInt(qr);
            
            $('#visualcontroller .time'+parseInt(togo)+' a').fadeTo(300,0, function () {
                
                $('#visualcontroller .time'+parseInt(togo)+' a').removeClass("noactive").addClass("active");
                $('#visualcontroller .time'+parseInt(togo)+' a span').removeShadow();
                if( $.browser.msie )
                {
                    $('#visualcontroller .time'+parseInt(togo)+' a span').css({
                        'background' : 'none'
                        //'filter' : 'Shadow(Color=#FFFFFF, Direction=-180, Strength=1.1)'
                        
                    });
                }
                else{
                    $('#visualcontroller .time'+parseInt(togo)+' a span').dropShadow({left: 0, top: 1, blur: 0, opacity : 0.7, color: "#FFFFFF", swap: false});
                }
                
                
                $('#visualcontroller .time'+parseInt(togo)+' a').fadeTo(300,1, function () {
                    timetoleave = togo;
                    timetogo = (togo + 1) >= (times+1) ? 1 : (togo + 1);
                    onmoving = 0;
                });
            });
        });*/
    }
    function moveTimeSlider ( posit, q ){
        //console.log(posit);
        //console.log( 'moveTimeSlider = position: '+(190*posit)+' and go to time: '+q );
        $('#visualcontroller .slider').animate(
            { left: ( parseInt((190)*posit) ) },
            1200,'swing',
            function(){
                if( q == parseInt(times) )
                {
                    //$('visualcontroller .slider').css({left: -968});
                    //alert('qui');
                    quant3=1;
                }
                onmoving = 0;
                if( executing == 0 ){
                    startTime();
                    executing = 1;
                }
            }
        );
        quant3 = posit == 0 ? 2 : q+1;
    }
    
    function timeLineControl( ttl, ttg, qu )
    {
        onmoving =1;
        fadeTime(ttl,ttg);
        maisottozero = ( parseInt(qu-1) <= 0 ) ? 0 : (qu-1);
        moveTimeSlider ( maisottozero, qu );
    }
    
    function startTime ( )
    {
        $(document).everyTime(7000, function() {
            takeLeft(quant);
            takeLeft2(quant2);
            timeLineControl(timetoleave, timetogo, quant3);
        }, 3000000);
        executing = 1;
    }
    
    function attentionRight ( elem )
    {
        //console.log( 'chiamata' );
        $(elem).everyTime(100, function() {
            if ( parseInt(  $(elem).css('left').replace('px','')    ) >= 140 )
            {
                //console.log( 'va qui' );
                $(elem).stop();
            }
        }, 3000000);
    }
    function attentionLeft ( elem )
    {
        //console.log( 'chiamata' );
        
        $(elem).everyTime(100, function() {
            if ( parseInt(  $(elem).css('left').replace('px','')    ) <= -350 )
            {
                //console.log( 'va qui 2' );
                $(elem).stop();
            }
        }, 3000000);
    }
    
    
    //ENDS VISUAL CAROUSELS
    
    $(document).ready(function(){
        
        startTime();
        
        
        //if( $.browser.msie && parseInt( $.browser.version )<=7 )
        if( $.browser.msie )
        {
            $('#visualcontroller a span').css({
                'background' : 'none'
               // 'filter' : 'Shadow(Color=#222222, Direction=-180, Strength=1.5)'
                
            });
            $('#visualcontroller a.active span').css({
                'background' : 'none'
                //'filter' : 'Shadow(Color=#FFFFFF, Direction=-180, Strength=1.1)'
                
            });
        }
        else
        {
            if( $('#visualcontroller a span').dropShadow({left: 0, top: 1, blur: 0, opacity : 0.7, color: "#000000", swap: false}) )
            {
                if( $('#visualcontroller a.active span').removeShadow() )
                {
                    $('#visualcontroller a.active span').dropShadow({left: 0, top: 1, blur: 0, opacity : 0.7, color: "#FFFFFF", swap: false});
                }
            }
        }
    $('a[href*=#hometext]').click(function() {
        if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
            var $target = $(this.hash);
            $target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
            if ($target.length) {
                var targetOffset = $target.offset().top;
                $('html,body').animate({scrollTop: targetOffset}, 1000);
                return false;
            }
        }
    });
        
        $('.platformcarouselcontainer .prev a').mouseenter(function(){
            
            //console.log( parseInt($('.platformsimage').css('left').replace('px','')) );
            
            
            if ( parseInt($('.platformsimage').css('left').replace('px','')) <= parseInt(140) )
            {
                $('.platformsimage').animate({ left: parseInt( $('.platformsimage').width() ) + "px" }, (950 * 10), "linear", function() {
                    
                });
                attentionRight('.platformsimage');
            }
            else{
                $('.platformsimage').stopTime();
            }
            
        }).mouseleave(function(){
            $('.platformsimage').stop().stopTime();
        });
        
        $('.platformcarouselcontainer .next a').mouseenter(function(){
            if ( parseInt($('.platformsimage').css('left').replace('px','')) >= -parseInt(350) )
            {
                $('.platformsimage').animate({ left: -parseInt( $('.platformsimage').width() ) + "px" }, (950 * 10), "linear", function() {
                    
                });
                attentionLeft('.platformsimage');
            }
            else{
                $('.platformsimage').stopTime();
            }
        }).mouseleave(function(){
            $('.platformsimage').stop().stopTime();
        });
        $('#visualcontroller li a').click(function(){
            if( onmoving == 0 ){
                $(document).stopTime();
                executing = 0;
                takeLeft(parseInt( $(this).parents().attr('goto') ));
                takeLeft2(parseInt( $(this).parents().attr('goto') ));
                timeLineControl(timetoleave, parseInt( $(this).parents().attr('goto') ), parseInt( $(this).parents().attr('goto') ));
            }
        });
    });
