var PO_TIMER_SECONDS = 6000;
var po_timer;

function handlePromotionalOfferSwap(e)
{
	var element = getElementByEvent(e);
	
	if (element.id.indexOf(PROMOTIONAL_OFFER_PREFIX) != 0)
	{
		element = element.parentNode;
	}
		
	if (element.id == PROMOTIONAL_OFFER_PREVIOUS)
	{
		changePromotionalOfferDiv(-1);
	}
	else
	{
		changePromotionalOfferDiv(1);
	}
	cancelEventCompletion(e);
	return false;
}

function setDivSwapPOTimer(swapDiv)
{
	if (swapDiv == null)
	{
		swapDiv = true;
	}

	if (swapDiv)
	{
		changePromotionalOfferDiv(1);
	}	
}

function changePromotionalOfferDiv(direction)
{
	var loopDiv = false;
	var maxDivId = 0;
	var loopDivId = 0;
	var currentDivId = 0;
	var newCurrentDivId = 0;

	clearTimeout(po_timer);

	if (direction != 0)
	{
		do
		{
			maxDivId = loopDivId;
			loopDivId++;
			loopDiv = getPromotionalOfferDiv(loopDivId);
			if (loopDiv)
			{
				if (loopDiv.className.search(PROMOTIONAL_OFFER_HIDDEN) < 0)
				{
					currentDivId = loopDivId;
				}
			}
		} 
		while (loopDiv)

		if (maxDivId > 1 && currentDivId > 0)
		{
			if (direction != -1)
			{
				direction = 1;
			}
			
			newCurrentDivId = currentDivId + direction;
			
			if (newCurrentDivId < 1)
			{
				newCurrentDivId = maxDivId;
			}
			else if (newCurrentDivId > maxDivId)
			{
				newCurrentDivId = 1;
			}
			
			var element = getPromotionalOfferDiv(newCurrentDivId);
			
			for (var i = 1; i <= maxDivId; i++)
			{
				var element = getPromotionalOfferDiv(i);
				
				if (i != newCurrentDivId)
				{
					element.className = PROMOTIONAL_OFFER_HIDDEN;
				}else
				{
					element.className = "";
				}
			}			
		}
	}
	
	po_timer = setTimeout("setDivSwapPOTimer()", PO_TIMER_SECONDS);
}

function getPromotionalOfferDiv(index)
{
	return document.getElementById(PROMOTIONAL_OFFER_PREFIX + index);
}
