/*
 * Slide animation
 */
 
var oldAd = 'unset';
var currentAd = 'unset';
var header = 'unset';
var content = 'unset';
var n = 2;
var time = 5000;
var hold = 3500;
var direction = 'right';

function slideAnimationImage(){
	currentAd = "img-" + n;
	if(oldAd != 'unset')
		$("#animation").removeClass(oldAd);
	switchAnimationText();
	$("#animation").addClass(currentAd);
	$("#animation").show("slide", { direction: direction }, time, slideCallback);		
}

function switchAnimationText(){					
	header = text[n]['header'];
	content = text[n]['content'];
	$("#animation-text div.below").css("opacity", 0); 
	$("#animation-text div.above").css("opacity", 1); 
	$("#animation-text div.below span.header").html(header);
	$("#animation-text div.below span.content").html(content);
	$("#animation-text div.below").fadeTo(time, 1);
	$("#animation-text div.above").fadeTo(time, 0);
}

function slideCallback(){	
	header = $("#animation-text div.below span.header").html();
	content = $("#animation-text div.below span.content").html();
	$("#animation-text div.above span.header").html(header);
	$("#animation-text div.above span.content").html(content);
	
	$(".underlay").removeClass(oldAd);	
	$(".underlay").addClass(currentAd);
	oldAd = currentAd;
	if(n == adMax)
		n = 1;
	else
		n++;
	var t=setTimeout("slideAnimationImage()", hold);
}

function setStartAnimationText(){
	header = text[1]['header'];
	content = text[1]['content'];
	$("#animation-text div.above span.header").html(header);
	$("#animation-text div.above span.content").html(content);				
}

function attachSlide(){
	setStartAnimationText();
	var t=setTimeout("slideAnimationImage()", hold);	
}
