function FeatureRoll(config) {
	this.initialize(config);
}
FeatureRoll.prototype = {
	initialize : function(config) {
		this._scrollDelay = config.scrollDelay;
		this._nitems = config.nitems;
		this._npanes = config.npanes;
		this._currentPane = 0;
		this._paneScrollTimer = null;
		this._scrollDuration = (config.scrollDuration || 8000) / 1000; // ms to s
		this._effect = null;
		this._scrollablePane = config.scrollablePane
				|| $('featured_content_scrollable');
		this._allPanes = config.allPanes || $$('.ind_pane');
	},
	scrollToPane : function(pane_number) {
		var selected_pane = this._allPanes[pane_number];
		var offset = selected_pane.positionedOffset();

		var duration = this._scrollDuration;
		if (this._effect) {
			this._effect.cancel();
		}

		this._effect = new Effect.Morph(this._scrollablePane, {
					style : 'left:' + -offset[0] + 'px; top:' + -offset[1]
							+ 'px;',
					duration : duration
				});
	},
	setPane : function(pane_number) {
		var selected_pane = this._allPanes[pane_number];
		var offset = selected_pane.positionedOffset();

		if (this._effect) {
			this._effect.cancel();
		}

		this._scrollablePane.setStyle({
					left : (-offset[0] + 'px'),
					top : (-offset[1] + 'px')
				});
	},
	scrollToNextPane : function() {
		this.scrollToNextPaneAndStop();
		this.setNextPaneScrollTimeout();
	},
	scrollToNextPaneAndStop : function() {
		clearTimeout(this._paneScrollTimer);
		if (this._currentPane == (this._npanes - 1)) {
			this._currentPane = 0;
			if (!this.isEffectRunning()) {
				this.setPane(this._currentPane);
			}
		}
		this._currentPane++;
		this.scrollToPane(this._currentPane);
	},
	scrollToPreviousPaneAndStop : function() {
		clearTimeout(this._paneScrollTimer);
		if (0 == this._currentPane) {
			this._currentPane = this._npanes - 1;
			if (!this.isEffectRunning()) {
				this.setPane(this._currentPane);
			}
		}
		this._currentPane--;
		this.scrollToPane(this._currentPane);
	},
	scrollToPreviousPane : function() {
		this.scrollToPreviousPaneAndStop();
		this.setNextPaneScrollTimeout();
	},
	setNextPaneScrollTimeout : function() {
		this._paneScrollTimer = setTimeout(this.scrollToNextPane.bind(this), this._scrollDelay);
	},
	isEffectRunning : function() {
		return (this._effect && "finished" != this._effect.state);
	}
}
