function ticker(id) {
	this.id = id;
	this.tickerIV = null;
	
	this.options = { width:700, delay:16 };
	this.items = new Array();

	this.createItem = function(elem) {
		this.elem = elem;
		this.width = this.elem.offsetWidth;
		this.x = this.options.width;
		this.css = this.elem.style;
		this.css.width = this.width + 'px';
		this.css.left = this.x + 'px';
		
		this.move = function() {
			if(this.x > -this.width ) {
				this.x -= 3;
				this.css.left = this.x + 'px';
			}
			else {
				//reset
				this.x = this.options.width;
				this.css.left = this.x + 'px';
				//this.move = true;
			}
		}
	}

	this.load = function() {
		delete(this.items);
		this.items = new Array();
		var self = this; // for confusion fixing 
		$(this.id).children().each(function(items) {
			//alert($(this).text());
			self.items.push(self.createItem($(this).get(0)));
		});
	}

	//this.loadItems();
	//$('#Ticker').css('visibility', 'visible')
}
	
ticker.prototype.move = function() {
	for(var i = 0; i < this.Items.length; i++) {
		this.Items[i].move();
	}
}

ticker.prototype.start = function() {
	var self = this;
	this.tickerIV = setInterval(function() { self.move(); }, this.options.delay);
	$(this.id).css('visibility', 'visible')
}

ticker.prototype.stop = function() {
	if (this.tickerIV != null) {
		clearInterval(ticker.tickerIV);
		ticker.tickerIV = null;
		$(this.id).css('visibility', 'hidden')
	}
}
ticker.prototype.pause = function() {
	if (this.tickerIV != null) {
		clearInterval(ticker.tickerIV);
		ticker.tickerIV = null;
	}
}

ticker.prototype.reload = function() {
	
	this.stop();
	this.loadItems();
	this.start();
}


function createTickerEntry(tickerID, tickerWidth, tickerEntries) {
	var width = 0;
	var count = 0;
	var entry;

	while (width < (tickerWidth * 2)) {
		for(var i = 0; i < tickerEntries.length; i++) {
			entry =
				'<div id="divTickerEntry' + (count+1) + '" class="cssTickerEntry" ' +
				'style="position:absolute; top:2px; white-space:nowrap">' +
				//' ' + tickerSpacer + '&nbsp;' +
				tickerEntries[i] + 
				'</div>'

			$(tickerID).append(entry);
			//alert(tickerID + ' ' + '#divTickerEntry' + (count+1));
			width += $(tickerID + ' ' + '#divTickerEntry' + (count+1)).get(0).clientWidth;
			w.value = width;
			count++;
		}
		//alert(width);
	}
	return count;
}


