
var timeouts = new Object();
var idForms = new Object();
function rotateBanner(n,grp)
{
	//If we don't have a rotation timer, read it from the adrotation span
	if ((timeouts[grp]==-1) || (timeouts[grp]==null))
	{
		var t=document.getElementById(grp+"AdRotation");
		if (t!=null) timeouts[grp]=parseInt(t.innerHTML);
		var t=document.getElementById(grp+"AdGroup");
		if (t!=null) idForms[grp]=t.innerHTML;
	}
	if ((timeouts[grp] > 0) && (idForms[grp] != "") && (idForms[grp] != null))
	{
		//Make ads in group n invisible
		var i=1;
		var advert = document.getElementById(idForms[grp]+"_g"+n+"_ad"+i);
		while(advert != null)
		{
			advert.style.display = "none";
			i++;
			advert = document.getElementById(idForms[grp]+"_g"+n+"_ad"+i);
		}
		//Go to the negrpt group			
		n++;
		i=1;
		advert = document.getElementById(idForms[grp]+"_g"+n+"_ad"+i);
		if (advert == null)
		{
			n=1;
			advert = document.getElementById(idForms[grp]+"_g"+n+"_ad"+i);
		}
		//Count the ads in this group		
		while(advert != null)
		{
			i++;
			advert = document.getElementById(idForms[grp]+"_g"+n+"_ad"+i);
		}
		//Make a random one visible			
		var rnd = (1+Math.floor(Math.random()*(i-1)));
		//alert(idForm+"_g"+n+"_ad"+rnd+" - "+document.getElementById(idForm+"_g"+n+"_ad"+rnd));
		document.getElementById(idForms[grp]+"_g"+n+"_ad"+rnd).style.display = "";
		//Set a timer to cycle again
		setTimeout("rotateBanner("+n+",'"+grp+"');",timeouts[grp]); 
	}
}