var Coca = { initialize: function () {} };
Coca.initialize();

Coca.Marquee = Class.create({
	
	initialize: function () {
		this._content = $('marqueeContent');
		this._mask = $('marqueeMask');
		this._interval = null;
		this._positionStartX = this._mask.offsetWidth;
		this._setRealWidth(this._mask,this._content);
		this._positionEndX = this._content.offsetWidth*-1;
		Event.observe(this._content,'mouseover',this._stop.bind(this));
		Event.observe(this._content,'mouseout',this._setInterval.bind(this));
		this._setInterval();
	},
	
	_setRealWidth: function (mask,content) {
		var w = mask.offsetWidth;
		Element.setStyle(mask, { width:'5000px', position:'absolute' });		
		Element.setStyle(content, { width:content.offsetWidth+'px' });
		Element.setStyle(mask, { width:w+'px', position:'relative' });		
	},
	
	_setInterval: function (axis,move) {
		if (!this._interval) {
			this._interval = new PeriodicalExecuter(this._move.bind(this),0.01);
		}
		else {
			this._interval.callback = this._move.bind(this);
			this._interval.registerCallback();
		}
	},
	
	_move: function () {
		Element.setStyle(this._content,{ left:(this._content.offsetLeft-1)+'px' });
		if (this._content.offsetLeft<=this._positionEndX) {
			this._reset();
		}
	},
	
	_reset: function () {
		Element.setStyle(this._content,{ left:this._positionStartX+'px' });
	},
	
	_stop: function () {
		this._interval.stop();
	}
	
});

Event.observe(window,'load',function(){
	if ($('marqueeMask')) new Coca.Marquee();
});