Ticker.prototype.element = null;
Ticker.prototype.espan = null;
Ticker.prototype.newsBites = [];
Ticker.prototype.timeout = 5000;
Ticker.prototype.timeoutId = null;
Ticker.prototype.currentIndex = 0;

function Ticker(props) {
	this.element = document.getElementById(props.id);
	this.espan = this.element.getElementsByTagName("SPAN")[1];
	this.newsBites = props.items;
	this.timeout = props.timeout;
	var ticker = this;
	this.espan.onmouseover = function() { this.call_self("stopLooping"); }
	this.espan.onmouseout = function() { this.call_self("hideHeadline"); }
	this.currentIndex = 0;
}

Ticker.prototype.start = function() {
	// used to be load()
	Effect.Fade(this.espan);	
	setTimeout(this.call_self("showHeadline"), 1000);
}

Ticker.prototype.showHeadline = function() {
	this.espan.innerHTML = this.newsBites[this.currentIndex];
	Effect.Appear(this.espan, { duration : 3.0 });
	this.currentIndex = (this.currentIndex + 1) % this.newsBites.length;
	this.timeoutId = setTimeout(this.call_self("hideHeadline"), this.timeout);
}

Ticker.prototype.hideHeadline = function() {
	Effect.Fade(this.espan, { duration : 0.8 });
	setTimeout(this.call_self("showHeadline"), 1200);
}

Ticker.prototype.stopLooping = function() {
	clearTimeout(this.timeoutId);
}

Ticker.prototype.call_self = function(fname, args) {
	var ticker = this;
	return function() { ticker[fname](args); }
}
