/* GLOBAL VARIABLES */
var logoFadeInSpeed = 200;
var logoFadeOutSpeed = 100;

var logoTimer;
var logoTimerDuration = 45;
var logoStep = 1;
var logoStepMax = 6;
var logoOffset = 70;

var randomQuotes = new Array(
	'not about procrastination.',
	'diving into his mind.',
	'dreaming of a french baguette.',
	'watching a tree.',
	'watching three clouds.',
	'having an idea.',
	'having two ideas.',
	'having no ideas.',
	'not fighting a walrus.',
	'having a swim.',
	'making a salad.',
	'not liking shaky trains.'
);

jQuery(document).ready(function(){

	//--- BAROUSELITE
	$('div.barouselite').each(function(n){
		if($(this).hasClass('fast')){
			$(this).barouselite({
				slideDuration: 2000
			});	
		}else{
			$(this).barouselite();	
		}		
	});

	//--- LOGO ROLLOVER
	jQuery('h1 a').hover(
      function () {
      	animSprite("h1 a", 1, logoTimerDuration, logoOffset, logoStepMax);      	
      }, 
      function () {      	
        animSprite("h1 a", 0, logoTimerDuration, logoOffset, logoStepMax);
      }
    );
    
    //--- RANDOM QUOTE
    loadRandomQuote();
    
    //--- TAG CLOUD ROLLOVER
    jQuery('#tag_cloud_list a').hover(function(){
    	var currentIndex = jQuery(this).index();    	    	
    	var linkBwZone1 = jQuery(this).parent().find('a:eq('+ parseInt(currentIndex - 1) +')');
    	var linkBwZone2 = jQuery(this).parent().find('a:eq('+ parseInt(currentIndex - 2) +')');
    	var linkFwZone1 = jQuery(this).parent().find('a:eq('+ parseInt(currentIndex + 1) +')');
    	var linkFwZone2 = jQuery(this).parent().find('a:eq('+ parseInt(currentIndex + 2) +')');
    	
    	if(linkBwZone1.length > 0) linkBwZone1.addClass('zone1');
    	if(linkBwZone2.length > 0) linkBwZone2.addClass('zone2');
    	if(linkFwZone1.length > 0) linkFwZone1.addClass('zone1');
    	if(linkFwZone2.length > 0) linkFwZone2.addClass('zone2');
    }, function(){
    	jQuery('#tag_cloud_list a').removeClass('zone1').removeClass('zone2');
    });
});

function loadRandomQuote(){
	var iPosition = Math.floor(Math.random()*randomQuotes.length);
	jQuery('#blurb').text(randomQuotes[iPosition]);
}

function animSprite(selector, direction, speed, offset, stepMax){			
	if(direction == 1){
		window.clearTimeout(logoTimer);
		//Going forward
		logoStep++;
		var pos = -(parseInt(logoStep) * parseInt(offset));
		//console.log("[1] " + logoStep);
		
		jQuery(selector).css('background-position', "0px " + pos + "px");
		
		if(parseInt(logoStep) < parseInt(stepMax)){
			var nextStepCall = function () { animSprite(selector, direction, speed, offset, stepMax); };
	    	logoTimer = window.setTimeout(nextStepCall, speed);	
			//timer = window.setTimeout('animSprite(1)', speed);			
		}else{
			window.clearTimeout(logoTimer);
		}		
	}else{		
		//Going backward
		window.clearTimeout(logoTimer);
		logoStep--;
		var pos = -(parseInt(logoStep) * parseInt(offset));
		//console.log("[0] " + logoStep);
		
		jQuery(selector).css('background-position', "0px " + pos + "px");
		
		if(parseInt(logoStep) > 0){
			var nextStepCall = function () { animSprite(selector, direction, speed, offset, stepMax); };
	    	logoTimer = window.setTimeout(nextStepCall, speed);	
			//animEyesTimer = window.setTimeout('AnimEyes(0)', animEyesTimerDuration);			
		}else{
			window.clearTimeout(logoTimer);
		}
	}	
}
