var Marquee = Class.create();
Marquee.prototype = {
	initialize: function (container, element, fps) {
		this.container = $(container);
		this.element = $(element);
		this.fps = fps;
		this.scrolling = true;
		
		if (!this.container || !this.element || isNaN(this.fps) || (fps <= 0))
			return false;
		
		this.stopScrolling = function () {
			this.scrolling = false;
		}.bind(this);
		this.resumeScrolling = function () {
			this.scrolling = true;
		}.bind(this);
		
		this.pe = new PeriodicalExecuter(this.scroll.bind(this), 1/fps);
		Event.observe(this.container, 'mouseover', this.stopScrolling);
		Event.observe(this.container, 'mouseout', this.resumeScrolling);
		Event.observe(window, 'unload', this.deinitialize.bind(this));
	},
	
	scroll: function (pe) {
		if (!this.scrolling)
			return;
		
		var marqueeWidth = parseInt(this.element.getStyle('width'));
		var marqueeLeft = parseInt(this.element.getStyle('marginLeft')) - 4;
		
		this.element.setStyle({marginLeft: (marqueeWidth + marqueeLeft > 0 ? marqueeLeft : parseInt(this.container.getWidth())) + 'px'});
	},
	
	deinitialize: function () {
		this.scrolling = false;
		if (this.pe)
			this.pe.stop();
		
		Event.stopObserving(this.container, 'mouseover', this.stopScrolling);
		Event.stopObserving(this.container, 'mouseout', this.resumeScrolling);
		
		delete this.container;
		delete this.element;
		delete this.fps;
		delete this.pe;
		delete this.scrolling;
		
		delete this.stopScrolling;
		delete this.resumeScrolling;
	}
};