/* Globals
-------------------------------------------------------------- */
var timeoutSwitcher;
var titles;
var texts;
var lastIndex = 0;
var currentIndex = 0;
var isAbout = false;
var aboutIndex = 0;

/* Functions
-------------------------------------------------------------- */

function initLogoSwitcher(){
	
	// check if about text
	if (document.location.href.indexOf("mike-meire") != -1){
		aboutIndex = 0;
		isAbout = true;
	}
	if (document.location.href.indexOf("meire-und-meire") != -1){
	  	aboutIndex = 1;
		isAbout = true;
	}
	if (document.location.href.indexOf("neo-noto") != -1){
	  	aboutIndex = 2;
		isAbout = true;
	}
	
	if(isAbout == true){
		intervalTimerLogo = 1;
	}
	
	// get titles+text
	titles = $('#logo ul li .active');
	texts = $('#logo .description');
	
	if(isAbout == false){
		
		// show first
		$(titles[0]).css({'display':'block'});
		$(texts[0]).css({'display':'block'});
		
		// start auto switch
		timeoutSwitcher = setTimeout("next()", intervalTimerLogo);
		
	}else{
		
		// show first
		$(titles[aboutIndex]).css({'display':'block'});
		$(texts[aboutIndex]).css({'display':'block'});
		
	}
	
	// interaction
	
	// click thumbnails gallery
	$('#logo ul li').each(function(index) {
		
		$(this).hover(function() {
			
			// stop auto switch
			clearTimeout(timeoutSwitcher);
			
			// fade out last
			if(index!=currentIndex){
				$(titles[currentIndex]).stop(true, true).customFadeOut(speedHoverLogo);
				$(texts[currentIndex]).stop(true, true).customFadeOut(speedHoverLogo);
			}
			// fade in current
			$(titles[index]).stop(true, true).customFadeIn(speedHoverLogo);
			$(texts[index]).stop(true, true).customFadeIn(speedHoverLogo);
			// current index
			currentIndex = index;
		}, function() {
			// last
			lastIndex = currentIndex;
			// restart timeoutSwitcher
			timeoutSwitcher = setTimeout("next()", intervalTimerLogo);
		});
		
	});
	
}

function next(){
	
	// current index
	if(isAbout == false){
		currentIndex++
		if(currentIndex >= titles.length){
			currentIndex = 0;
		}
	}else{
		currentIndex = aboutIndex;
	}
	
	// just if not last is not current
	if(lastIndex != currentIndex){
		// fade out old + fade in new
		$(titles[lastIndex]).customFadeOut(speedAutoFadeLogo);
		$(texts[lastIndex]).customFadeOut(speedAutoFadeLogo);

		$(titles[currentIndex]).customFadeIn(speedAutoFadeLogo);
		$(texts[currentIndex]).customFadeIn(speedAutoFadeLogo);

		// reset last index
		lastIndex = currentIndex;
	}
	
	// restart auto switch
	timeoutSwitcher = setTimeout("next()", intervalTimerLogo);
	
}
