var ScrollTicker = new Class({

	Implements: [Events, Options],

	options: {
		velocity: 0.02,
		startHidden: true
	},
	
	initialize: function(element, options) {
		this.setOptions(options);
		this.element = $(element);
		this.tickerWidth = this.element.getSize().x;
		this.ticker = new Element('div', {'class': 'scroll-ticker', 'styles': {'overflow': 'hidden', 'white-space': 'nowrap', 'width': this.tickerWidth}}).wraps(this.element); 
		this.elementWidth = 0;
		this.element.getChildren().each(function(child){		
			this.elementWidth += child.setStyle('float', 'left').getSize().x;
		}, this);
		this.element.setStyles({
			'width': this.elementWidth,
			'margin-left': (this.options.startHidden ? this.tickerWidth : 0)
		});
		
		this.timing = this.elementWidth / this.options.velocity;
		this.total = this.elementWidth;
		
		this.element.set('tween', {'property': 'margin-left', 'duration': this.timing, 'transition': 'linear', 'onComplete': function(){this.scroll();}.bind(this)});
		
		this.ticker.addEvents({
			'mouseenter': function(){
				this.element.get('tween').pause();
			}.bind(this),
			'mouseleave': function(){
				this.element.get('tween').resume();
			}.bind(this)
		});
		
		this.scroll();
	},
	
	scroll: function() {
		this.element.get('tween').start(this.tickerWidth, -this.total);
	}
});