var Ticker = Class.create();
Ticker.prototype = {
	initialize: function(id, options) {
  		this.wrapper = $(id);
  		this.wrapper.innerHTML = '<div>' + this.wrapper.innerHTML + '</div>';
  		this.innerLength = this.wrapper.innerHTML.length*5;
		this.options = $H({
			speed:	6,
			height: 25
		}).merge(options);
		this.width = this.wrapper.getWidth();
		this.offset = (this.width);
		this.content = $(this.wrapper.down(0));
		this.wrapper.setStyle({
			overflow: 'hidden',
			height: this.options.height+'px',
			lineHeight: this.options.height+'px'
		});
		this.content.setStyle({
			marginLeft : this.offset+'px'
		});
		this.hover = false;
		
		Event.observe(this.wrapper, 'mouseover', this.over.bind(this));
		Event.observe(this.wrapper, 'mouseout', this.out.bind(this));
		
		new PeriodicalExecuter(this.check.bind(this), .1);
	},
  	check: function () {
  		if (!this.hover) {
  			this.content.style.marginLeft = this.offset+'px';
  			if ((this.width+this.innerLength) <= (-1*this.offset)) {
  				this.offset = this.width;
  			}
  			else {
  				this.offset -= this.options.speed;
  			}      			
  		}
  	},
  	over: function () { this.hover = true; },
  	out: function () { this.hover = false; }
};

Event.observe(window, 'load', function () {
	$$('div.Ticker').each(function (thisScroller) {
		new Ticker(thisScroller);
	});
});