// ---------------------------
// Prerequisite: <Ajax.js>
// ---------------------------

var bannerList = new Array();
var timerID = null;
var delay = 10;

var inInterval = false;

/* ms = millisecondi di attesa
		url = url da interrogare
		id = id dell'elemento html da aggiornare
		property = proprietà dell'elemento da aggiornare, ad esempio 'src' o 'innerHTML'
*/
function Banner(ms, url, id, property)
{
	if (!Exists(id))
	{
		b = new BannerRequest(ms, url, id, property);
		bannerList.push(b);
		if (timerID == null)
		{
			timerID = setInterval("OnInterval()", delay);
		}
	}	
	
}

function Exists(id)
{
	for (var i=0; i<bannerList.length; i++)
	{
		var ban = bannerList[i];
		if (ban.id == id)
			return true;
	}
	return false;
}


function OnInterval()
{
	//if (timerID) clearInterval(timerID);
	if (inInterval) return;
	inInterval = true;
	
	for (var i=0; i<bannerList.length; i++)
	{
		var ban = bannerList[i];
		ban.count = ban.count - 1;
		if (ban.count <= 0)
		{
			ban.count = ban.ms;		
			var id = ban.id;
			var url = ban.url;
			var prop = ban.property;
			
			//new Ajax("GET", url, id, prop);
			Request(url, id, prop);
		}	
	}
	
	inInterval = false;
	//timerID = setInterval("OnInterval()", delay);

}

BannerRequest = function (ms, url, id, property)
{
	this.ms = ms;
	this.url = url;
	this.id = id;
	this.property = property;
	this.count = ms;	
}


