
var currentDiv;
var currentDivTh;
var currentDivThumb;
var currentFlag;

function startAnimation()
{
	currentDiv = "feature1";
	currentDivTh = "thumb1";
	currentDivThumb = "thumb4";
	currentFlag = 0;
	document.getElementById(currentDiv).style.visibility = "visible";
	document.getElementById("thumb1").style.opacity = "1";
	document.getElementById("thumb1").style.filter = "alpha(opacity=100)";
	window.setTimeout("rotate("+currentFlag+")", 2000);
}


function fadeOut(divID, opacity, factor, wait)
{
	var div = document.getElementById(divID);
	
		if(div === "feature1")
			currentDivTh = "thumb1";
		else if(div === "feature2")
			currentDivTh = "thumb2";
		else if(div === "feature3")
			currentDivTh = "thumb3";
		else if(div === "feature4")
			currentDivTh = "thumb4";
		var divth = document.getElementById(currentDivTh);
		
		if(div === "feature1")
			currentDivThumb = "thumb4";
		else if(div === "feature2")
			currentDivThumb = "thumb1";
		else if(div === "feature3")
			currentDivThumb = "thumb2";
		else if(div === "feature4")
			currentDivThumb = "thumb3";
		var divthumb = document.getElementById(currentDivThumb);
		
		
	if(opacity >= 0)
	{
		div.style.opacity = opacity/100;
		div.style.filter = "alpha(opacity:"+opacity+")";
		//divthumb.style.opacity = "0.4";
		//divthumb.style.filter = "alpha(opacity=40)";
		opacity = opacity - factor;
		
		window.setTimeout("fadeOut('"+divID+"',"+opacity+","+factor+","+wait+")", wait);
		
		//fadeOutThumb("thumb1",100,5,100)
	}
	else
	{
		div.style.visibility = "hidden";
		
		//divth.style.opacity = "0.4";
		//divth.style.filter = "alpha(opacity=40)";
		
	}
}

function fadeIn(divID, opacity, factor, wait)
{
	if (currentDiv === divID)
	{
		var div = document.getElementById(divID);
		
		if(currentDiv === "feature1")
			currentDivTh = "thumb1";
		else if(currentDiv === "feature2")
			currentDivTh = "thumb2";
		else if(currentDiv === "feature3")
			currentDivTh = "thumb3";
		else if(currentDiv === "feature4")
			currentDivTh = "thumb4";
		var divth = document.getElementById(currentDivTh);
		
		//fadeOutThumb(currentDivTh,100,5,100)
		
		div.style.visibility = "visible";
		
		if(opacity <= 100)
		{
			div.style.opacity = opacity/100;
			div.style.filter = "alpha(opacity:"+opacity+")";
			
			divth.style.opacity = opacity/40;
			divth.style.filter = "alpha(opacity:"+opacity+")";
			
			opacity = opacity + factor;

			window.setTimeout("fadeIn('"+divID+"',"+opacity+","+factor+","+wait+")", wait);
		}
	}
}



function rotate(flag)
{
	if (flag == currentFlag)
	{
		fadeOut(currentDiv,95,5,100);
		
		if(currentDiv === "feature1")
			currentDiv = "feature2";
		else if(currentDiv === "feature2")
			currentDiv = "feature3";
		else if(currentDiv === "feature3")
			currentDiv = "feature4";
		else if(currentDiv === "feature4")
			currentDiv = "feature1";
		
		fadeIn(currentDiv,5,5,100);
		
		window.setTimeout("rotate("+flag+")", 8000);
	}
}



function userRotate(divID)
{
	if(currentDiv !== divID)
	{
		currentFlag++;
		fadeOut(currentDiv,80,20,50);
		currentDiv = divID;
		fadeIn(divID,25,25,50);
		window.setTimeout("rotate("+currentFlag+")", 8000);
	}
}


function fadeOutThumb(divID, opacity, factor, wait)
{
	
		if(divID === "feature1")
			currentDiv = "thumb4";
		else if(divID === "feature2")
			currentDiv = "thumb1";
		else if(divID === "feature3")
			currentDiv = "thumb2";
		else if(divID === "feature4")
			currentDiv = "thumb3";
	
	var div = document.getElementById(currentDiv);
			
	if(opacity >= 0)
	{
		div.style.opacity = opacity/100;
		div.style.filter = "alpha(opacity:"+opacity+")";
		opacity = opacity - factor;
		window.setTimeout("fadeOutThumb('"+currentDiv+"',"+opacity+","+factor+","+wait+")", wait);
	}
	else
	{
		//div.style.visibility = "hidden";
		//document.getElementById(div).style.visibility = "visible";
		//document.getElementById(div).style.opacity = "1";
		//document.getElementById(div).style.filter = "alpha(opacity=100)";
	}
}


