
var aTickers = new Array();

function CTicker_Tick(id)
{
	var ticker = aTickers[id];
	var text = ticker.headlines[ticker.currentHeadline];

	if (ticker.currentChar == 0)
	{
		if (ticker.link.Paused)
		{
			setTimeout("CTicker_Tick(" + ticker.nID + ")", ticker.speed);
			return;
		}
		ticker.link.href = ticker.urls[ticker.currentHeadline];
		if (ticker.tooltips[ticker.currentHeadline])
			ticker.link.title = ticker.tooltips[ticker.currentHeadline];
		else
			ticker.link.title = "";
	}

	ticker.currentChar++;
	if (ticker.currentChar > text.length)
	{
		ticker.currentChar = 0;
		ticker.currentHeadline++;
		if (ticker.currentHeadline >= ticker.headlines.length)
			ticker.currentHeadline = 0;
		setTimeout("CTicker_Tick(" + ticker.nID + ")", ticker.speed * ticker.pause);
	}
	else
	{
		ticker.text.nodeValue = text.substr(0, ticker.currentChar) + "_";
		setTimeout("CTicker_Tick(" + ticker.nID + ")", ticker.speed);
	}
}

function CTicker_AttachTo(elt)
{
	this.link = document.createElement("A");
	this.link.onmouseover = new Function("this.Paused = true");
	this.link.onmouseout = new Function("this.Paused = false");
	this.link.Paused = false;
	this.text = document.createTextNode("_");
	this.link.appendChild(this.text);
	elt.appendChild(this.link);

	setTimeout("CTicker_Tick(" + this.nID + ")", this.speed);
}

function CTicker_AddNews(headline, url, tooltip)
{
	this.headlines[this.headlines.length] = headline;
	this.urls[this.urls.length] = url;
	this.tooltips[this.tooltips.length] = tooltip;
}

function CTicker(speed, pause)
{
	this.AddNews = CTicker_AddNews;
	this.AttachTo = CTicker_AttachTo;
	this.Tick = CTicker_Tick;

	this.speed = speed ? speed : 50;
	this.pause = pause ? pause : 50;

	this.headlines = new Array();
	this.urls = new Array();
	this.tooltips = new Array();
	this.currentHeadline = 0;
	this.currentChar = 0;

	this.nID = aTickers.length;
	aTickers[this.nID] = this;
}

