/**
 * @name:			Text Ticker
 * @description: 	iterates through a list of copy for display
 * @requires:		DOM/DHTML objects in: /includes/javascript.js
 * @author: 		Rahmin Pavlovic
 * @date: 			2006-09-08
 * @version: 		2008-12-25
 *
 */

var tickerRef = null; // 'global' ref for each instance
function Ticker(containerID) {
	this.delay = 5;
	this.fade = 400;
	this.html = '';
	this.repeat = 1;
	this.counter = 0;
	this.timer = null;
	this.entry = [];
	this.containerID = containerID;
	this.ticker = DOM.getElementById(this.containerID);

	this.play = function() {
		if(this.ticker) {
			this.show();
			this.counter++;
			this.stop();

			if(this.counter == this.entry.length+1) {
				if(this.repeat) {
					this.counter = 0;
					this.play();
				}
			}
			else {
				tickerRef = this;
				this.timer = setTimeout('tickerRef.play()', this.delay*1000);
				tickerRef.length = 0; // destroy reference to free memory
			}
		}
	}

	this.show = function() {
		DOM.setOpacity(this.containerID, 0);
		this.ticker.innerHTML = this.entry[this.counter];
		DHTML.fade(this.containerID, 0, 100, this.fade);
	}

	this.start = function() {
		tickerRef = this;
		this.timer = setTimeout('tickerRef.play()', this.delay*1000);
		tickerRef.length = 0; // destroy reference to free memory
	}

	this.stop = function() {
		if(this.timer) {
			clearTimeout(this.timer);
		}
	}

	this.next = function() {
		this.stop();
		if(this.counter == this.entry.length) {
			this.counter = 0;
		}
		this.play();
	}

	this.prev = function() {
		this.stop();
		if(this.counter == 1) {
			this.counter = this.entry.length-1;
		}
		else {
			this.counter -= 2;
		}
		this.play();
	}
};