var currentAds=null;

function getNextAds()
{
	var item=null;
	
	if(currentAds)
		item=currentAds.next();
	
	if(!item)
	{
		var list=$$("#ads>div");
		if(list.length>0)
			item=list[0];
	};
	
	currentAds=item;
		
	return item;	
};

function switchAds()
{
	var d=0;
	if(currentAds)
	{
		Effect.Fade(currentAds);
		hideAds.delay(1,currentAds);
		d=1;
	};

	getNextAds();
	
	if(currentAds)
	{
		if(d>0)
			showAds.delay(d,currentAds);
		else
			showAds(currentAds);
	};

};

function showAds(elem)
{
	if(elem)
	{
		elem.style.opacity=0;
		Effect.Appear(elem);
		elem.show();
	};
};

function hideAds(elem)
{
	if(elem)
		elem.hide();
};

function init()
{
	switchAds();
	new PeriodicalExecuter(switchAds,8);
};


window.onload=init;