var fadeFlag = 0;

$(document).ready(function() {
	$('.icon-atria').mouseover(function(){ fadeFlag = 1; fadeSelection('.slideshow-atria'); $('.project-icons-arrow').attr('style','display: block; top: 0px!important'); });
	$('.icon-ingresso').mouseover(function(){ fadeFlag = 1; fadeSelection('.slideshow-ingresso'); $('.project-icons-arrow').attr('style','display: block; top: 95px!important'); });
	$('.icon-trilogi').mouseover(function(){ fadeFlag = 1; fadeSelection('.slideshow-trilogi'); $('.project-icons-arrow').attr('style','display: block; top: 190px!important'); });
	//$('.icon-amia').mouseover(function(){ fadeFlag = 1; fadeSelection('.slideshow-amia'); $('.project-icons-arrow').attr('style','display: block; top: 285px!important'); });
	
	$('.icon-atria').mouseout(function(){ fadeFlag = 0; fadeInNormal(); $('.project-icons-arrow').attr('style','display: none;'); });
	$('.icon-ingresso').mouseout(function(){ fadeFlag = 0; fadeInNormal(); $('.project-icons-arrow').attr('style','display: none;'); });
	$('.icon-trilogi').mouseout(function(){ fadeFlag = 0; fadeInNormal(); $('.project-icons-arrow').attr('style','display: none;'); });
	//$('.icon-amia').mouseout(function(){ fadeFlag = 0; fadeInNormal(); $('.project-icons-arrow').attr('style','display: none;'); });
	

	//$('.icon-ingresso').hoverIntent(fadeSelection('.slideshow-ingresso'), fadeInNormal);
	
	
	setInterval( "slideSwitch()", 5000 ); 
	setInterval( "slideIngressoSwitch()", 5000 ); 
	setInterval( "slideTrilogiSwitch()", 5000 ); 
	//setInterval( "slideAmiaSwitch()", 5000 ); 
	setInterval( "slideAtriaSwitch()", 5000 ); 
	//setInterval( "slideAxiomSwitch()", 5000 );  
});
		
function fadeInNormal(){
	$('#slideshow div').fadeOut(); 
	$('.slideshow-normal').fadeIn();
}

function fadeSelection(fader){
	$('#slideshow div').fadeOut();
	$(fader).fadeIn();	
}

function slideSwitch() {
	
    var $active = $('.slideshow-normal IMG.active');
    if ( $active.length == 0 ) $active = $('.slideshow-normal IMG:last');
    var $next =  $active.next().length ? $active.next()
        : $('.slideshow-normal IMG:first');
    $active.addClass('last-active');
    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
    if(fadeFlag == 0) {  
	    if($next.hasClass('default-banner-atria') == true) {
		    $('.project-icons-arrow').attr('style','display: block; top: 0px');
	    }  
	    else if($next.hasClass('default-banner-one-lygon') == true) {
		    $('.project-icons-arrow').attr('style','display: block; top: 95px');
	    }
	    else if($next.hasClass('default-banner-trilogi') == true) {
		    $('.project-icons-arrow').attr('style','display: block; top: 190px');
	    }
	    
	    //else if($next.hasClass('default-banner-amia') == true) {
		//    $('.project-icons-arrow').attr('style','display: block; top: 285px');
	    //}
	}     
}

function slideIngressoSwitch() {
    var $active = $('.slideshow-ingresso IMG.active');
    if ( $active.length == 0 ) $active = $('.slideshow-ingresso IMG:last');
    var $next =  $active.next().length ? $active.next()
        : $('.slideshow-ingresso IMG:first');
    $active.addClass('last-active');
    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });   
}

function slideTrilogiSwitch() {
    var $active = $('.slideshow-trilogi IMG.active');
    if ( $active.length == 0 ) $active = $('.slideshow-trilogi IMG:last');
    var $next =  $active.next().length ? $active.next()
        : $('.slideshow-trilogi IMG:first');
    $active.addClass('last-active');
    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });   
}

function slideAmiaSwitch() {
    var $active = $('.slideshow-amia IMG.active');
    if ( $active.length == 0 ) $active = $('.slideshow-amia IMG:last');
    var $next =  $active.next().length ? $active.next()
        : $('.slideshow-amia IMG:first');
    $active.addClass('last-active');
    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });   
}

function slideAtriaSwitch() {
    var $active = $('.slideshow-atria IMG.active');
    if ( $active.length == 0 ) $active = $('.slideshow-atria IMG:last');
    var $next =  $active.next().length ? $active.next()
        : $('.slideshow-atria IMG:first');
    $active.addClass('last-active');
    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });   
}

function slideAxiomSwitch() {
    var $active = $('.slideshow-axiom IMG.active');
    if ( $active.length == 0 ) $active = $('.slideshow-axiom IMG:last');
    var $next =  $active.next().length ? $active.next()
        : $('.slideshow-axiom IMG:first');
    $active.addClass('last-active');
    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });   
}

