PanoGlider = Class.create();
Object.extend(Object.extend(PanoGlider.prototype, Abstract.prototype), {
	initialize: function(wrapper, element, options){
		this.scrolling  = false;
		this.wrapper    = $(wrapper);
		this.options    = Object.extend({frequency: 3 }, options || {});
		this.element    = this.wrapper.down("#"+element);

		if(this.options.autoGlide)
			this.start();
	},

	stop: function() {
		if(this.scrolling)
			this.scrolling.cancel();
		clearTimeout(this.timer);

	},
	
	scroll: function() {
		var x = this.element.offsetWidth - this.wrapper.clientWidth - this.wrapper.scrollLeft;
		if(this.scrolling)
			this.scrolling.cancel();
		this.scrolling = new Effect.SmoothScroll(this.wrapper, {duration:this.options.frequency, x:x, y:0});
	},

	start: function() {
		this.periodicallyUpdate();
	},
	
	periodicallyUpdate: function() { 
		if (this.timer != null) {
			clearTimeout(this.timer);
		}
		this.scroll();
		this.timer = setTimeout(this.periodicallyUpdate.bind(this), (1+this.options.frequency)*1000);
	}
});

