
var daTicker = null;

var Ticker = new Class({

	options: {
		rightToLeft: true,
		speed: 1
	},

	initialize: function(el){
		dis = this;
		this.el = el;
		this.paused = false;
		// find the width of the container box
		this.startWidth = el.getSize().scrollSize.x;
		// create the inside box
		this.scroller = new Element('div', { 'id': 'ticker_scroller' }).injectInside(this.el);
		// move it to the right
		this.resetTick();
		this.scroller.addEvent('mouseover', function(){ dis.paused = true; });
		this.scroller.addEvent('mouseout', function(){ dis.paused = false; });
		new Ajax('/info/tickertext.html', {
			method: 'get',
			update: dis.scroller,
			evalScripts: true,
			onComplete: function(){
				dis.beginTick();
			}
		}).request();
	},

	beginTick: function(){
		this.fullWidth = this.scroller.getSize().size.x;
		this.tick();
	},

	resetTick: function(){
		this.scroller.setStyle('left', this.startWidth);
	},

	tick: function(){
		if (!this.paused) {

			if ((this.fullWidth + this.scroller.getStyle('left').toInt()) <= 0) {
				this.resetTick();
			} else {
				this.scroller.setStyle('left', (this.scroller.getStyle('left').toInt() + (this.options.speed * (this.options.rightToLeft ? -1 : 1))));
			}

		}
//		console.log(this.scroller.getStyle('left').toInt());
		window.setTimeout('daTicker.tick();', 15);
	}

});


window.addEvent('load', function(){
	if ($('ticker')) {
		daTicker = new Ticker($('ticker'));
	}
});

