
var currentDiv;
var currentFlag;

function startAnimation()
{
	currentDiv = "feature1";
	currentFlag = 0;
	document.getElementById(currentDiv).style.visibility = "visible";
	window.setTimeout("rotate("+currentFlag+")", 8000);
}

function startCompetitionAnimation()
{
	if(rotateCompetitions == true)
		window.setTimeout("rotateCompetition('competition1')", 8000);
}

function fadeOut(divID, opacity, factor, wait)
{
	var div = document.getElementById(divID);
	
	if(opacity >= 0)
	{
		div.style.opacity = opacity/100;
		div.style.filter = "alpha(opacity:"+opacity+")";
		opacity = opacity - factor;
		window.setTimeout("fadeOut('"+divID+"',"+opacity+","+factor+","+wait+")", wait);
	}
	else
	{
		div.style.visibility = "hidden";
	}
}

function fadeIn(divID, opacity, factor, wait)
{
	if (currentDiv === divID)
	{
		var div = document.getElementById(divID);
		
		div.style.visibility = "visible";
		
		if(opacity <= 100)
		{
			div.style.opacity = opacity/100;
			div.style.filter = "alpha(opacity:"+opacity+")";
			opacity = opacity + factor;
			window.setTimeout("fadeIn('"+divID+"',"+opacity+","+factor+","+wait+")", wait);
		}
	}
}

function fadeIn(divID, opacity, factor, wait)
{
	if (currentDiv === divID || divID === "competition1" || divID === "competition2")
	{
		var div = document.getElementById(divID);
		
		div.style.visibility = "visible";
		
		if(opacity <= 100)
		{
			div.style.opacity = opacity/100;
			div.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+")", 20000);
	}
}

function rotateCompetition(lastDiv)
{
		fadeOut(lastDiv,95,5,100);

		if(lastDiv === "competition1")
			lastDiv = "competition2";
		else if(lastDiv === "competition2")
			lastDiv = "competition1";
		
		fadeIn(lastDiv,5,5,100);
		
		window.setTimeout("rotateCompetition('"+lastDiv+"')", 5000);
}

function userRotate(divID)
{
	if(currentDiv !== divID)
	{
		currentFlag++;
		fadeOut(currentDiv,80,20,50);
		currentDiv = divID;
		fadeIn(divID,25,25,50);
		window.setTimeout("rotate("+currentFlag+")", 20000);
	}
}



