var countTowerAd = new Array();
var currentTowerAd = new Array();
var nextTowerAd = new Array();
var images = new Array();
function towerad_init() 
{
	for (a = 1; a <= 5; a++)
	{
		if (countTowerAd[a] == undefined) continue;
		if (parseInt(countTowerAd[a]) == 0) continue;
		if (!currentTowerAd[a]) 
		{
			currentTowerAd[a] = 1;
			$('towerad'+a+'_' + currentTowerAd[a]).setStyle( {display :'block'});
		}
	
		for (i = 2; i <= countTowerAd[a]; i++) 
		{
			$('towerad'+a+'_' + i).setStyle( {display :'none'});
		}
	}
	new PeriodicalExecuter(changeTowerAd, 7);
}

function changeTowerAd() 
{
	for (a = 1; a <= 5; a++)
	{
		if (countTowerAd[a] == undefined) continue;
		if (parseInt(countTowerAd[a]) == 0) continue;
		if (currentTowerAd[a] == countTowerAd[a]) 
		{
			nextTowerAd[a] = 1;
		} 
		else 
		{
			nextTowerAd[a] = currentTowerAd[a] + 1;
		}
	}
	// new Effect.Opacity($('towerad'+currentTowerAd), {duration:0.3, from:1.0, to:0.0,sync: false, afterFinish: hide,queue: {position: 'front', scope:'towerAd'}});
	hide();
	show();
}

function hide() 
{
	for (a = 1; a <= 5; a++)
	{
		if (countTowerAd[a] == undefined) continue;
		if (parseInt(countTowerAd[a]) == 0) continue;
		$('towerad'+a+'_' + currentTowerAd[a]).setStyle( {display :'none'});
	}
	// new Effect.Opacity($('towerad'+nextTowerAd), {duration:0.3, from:0.0, to:1.0,sync: false, beforeUpdate: show,queue: {position: 'front', scope: 'towerAd'}});
}

function show() 
{
	for (a = 1; a <= 5; a++)
	{
		if (countTowerAd[a] == undefined) continue;
		if (parseInt(countTowerAd[a]) == 0) continue;
		$('towerad'+a+'_' + nextTowerAd[a]).setStyle( {display :'block'});
                if($$('#towerad'+a+'_' + nextTowerAd[a]+' > img ')){
                    $$('#towerad'+a+'_' + nextTowerAd[a]+' > img ').src = $$('#towerad'+a+'_' + nextTowerAd[a]+' > img ').src;
                }
		currentTowerAd[a] = nextTowerAd[a];
	}
}

Event.observe(window, 'load', towerad_init);