var RotatorTimer = null;
var RotatorTimerSpeed = 4000;
var RotatorTimerIniSpeed = 2000;
var RotatorTip = 0;
var RotatorTipOld = 0;
var RotatorTipCount	= 3;
var PoziceUkazateleDefault = 50;
var PoziceUkazatele	= PoziceUkazateleDefault;
var RotatorOpacityState = 0;
var RotatorOpacityStep 	= 5;
var RotatorOpacitySpeed = 75;
var RotatorOpacityTimer = null;


function gObject(obj){
return document.getElementById(obj);	
}

function StartTipRotator()
{
	SetRotatorTipOpacity(gObject("akce-0"), 100);

	if(RotatorTimer!=null)
	{
		clearTimeout(RotatorTimer);
		RotatorTimer = null;
	}
	RotatorTimer = setTimeout("RotateTip()", RotatorTimerIniSpeed);
}

function RotateTip()
{
	RotatorTipOld = RotatorTip;
	RotatorTip++;
	if(RotatorTip==RotatorTipCount)
	{
		RotatorTip = 0;
	}
	DisplayTip(RotatorTip, RotatorTipOld, RotatorTimerSpeed, false);
}

function ShowPromoTip(which)
{
	which = RotatorTip + which;
	if(which==RotatorTipCount)
	{
		which = 0;
	}
	if(which<0)
	{
		which = RotatorTipCount-1;
	}
	ShowPromoTipExact(which)
}

function ShowPromoTipExact(which)
{
	RotatorTipOld = RotatorTip;
	RotatorTip = which;
	DisplayTip(RotatorTip, RotatorTipOld, RotatorTimerIniSpeed, true);
}

function DisplayTip(nTip, oTip, oSpeed, SkipAnimation)
{
	clearTimeout(RotatorTimer);
	RotatorTimer = null;

	if(SkipAnimation)
	{

		if(RotatorOpacityTimer != null)
		{
			clearTimeout(RotatorOpacityTimer);
			RotatorOpacityTimer = null;
		}
		gObject("akce-" + oTip).style.visibility = "hidden";
		SetRotatorTipOpacity(gObject("akce-" + oTip), 0);

		gObject("akce-" + nTip).style.visibility = "visible";
		SetRotatorTipOpacity(gObject("akce-" + nTip), 100);

		RotatorTimer = setTimeout("RotateTip()", oSpeed);
	}
	else
	{
		gObject("akce-" + nTip).style.visibility = "visible";

		ChangeTipOpacity();
	}

	var Navigace = gObject("promo-navigace").getElementsByTagName("SPAN")[0].getElementsByTagName("A");

	Navigace[oTip].setAttribute("class", "num");
	Navigace[oTip].setAttribute("className", "num");
	Navigace[nTip].setAttribute("class", "num act");
	Navigace[nTip].setAttribute("className", "num act");
}

function ChangeTipOpacity()
{
	clearTimeout(RotatorOpacityTimer);
	RotatorOpacityTimer = null;

	if(RotatorOpacityState>=100)
	{
		gObject("akce-" + RotatorTipOld).style.visibility = "hidden";
		RotatorOpacityState 	= 0;
		RotatorTimer 		= setTimeout("RotateTip()", RotatorTimerSpeed);
		return;
	}

	RotatorOpacityState += RotatorOpacityStep;

	SetRotatorTipOpacity(gObject("akce-" + RotatorTipOld), 100-RotatorOpacityState)
	SetRotatorTipOpacity(gObject("akce-" + RotatorTip), RotatorOpacityState)
		
	RotatorOpacityTimer = setTimeout("ChangeTipOpacity()", RotatorOpacitySpeed); 
}

function SetRotatorTipOpacity(oObj, opacity)
{
	try
	{
		oObj.style.opacity 	= (opacity / 100);
		oObj.style.MozOpacity 	= (opacity / 100);
		oObj.style.KhtmlOpacity = (opacity / 100);
		oObj.style.filter 	= "alpha(opacity=" + opacity + ")";

		if(opacity==100 && oObj.style.removeAttribute)
		{
			if(oObj.style.filter)
			{
				oObj.style.removeAttribute('filter');
			}
		}
	}
	catch(e)
	{
		return;
	}
}

