/*
 * Slide animation
 */
 
var oldAd = 'unset';
var currentAd = 'unset';
var header = 'unset';
var content = 'unset';
var oldMarginTop = 'unset';
var marginTop = 'unset';
var oldMarginLeft = 'unset';
var marginLeft = 'unset';
var n = 1;
var time = 5000;
var hold = 4500;
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'];
  marginTop = text[n]['margin-top'] + 'px';
  marginLeft = text[n]['margin-left'] + 'px';
	$("#animation-text div.below").css('margin-top', marginTop); 
	$("#animation-text div.below").css('margin-left', marginLeft); 
	$("#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;
  oldMarginTop = marginTop;
  oldMarginLeft = marginLeft;
	if(n == adMax)
		n = 0;
	else
		n++;
	var t=setTimeout("slideAnimationImage()", hold);
}

function setStartAnimationText(){
	header = text[0]['header'];
	content = text[0]['content'];
  marginTop = text[0]['margin-top'] + 'px';
  marginLeft = text[0]['margin-left'] + 'px';
	$("#animation-text div.above").css('margin-top', marginTop); 
	$("#animation-text div.above").css('margin-left', marginLeft); 
	$("#animation-text div.above span.header").html(header);
	$("#animation-text div.above span.content").html(content);
	$(".underlay").addClass("img-0");	
}

function attachSlide(){
  if(text.length > 0)
    setStartAnimationText();
  if(text.length > 1)
    var t=setTimeout("slideAnimationImage()", hold);	
  
}
