var FeatureRotator = new Class({
	Implements: Options,
	belt: {},
	features: [],
	current_pos: 0,
	waiting_clicks:0,
	options: {
		next: '',
		prev: '',
		width: 0,
		max_clicks: 3		
	},
	initialize: function(container, features, belt, options) {
		this.setOptions(options);
		this.belt = $$(belt)[0];
		this.features = $$(features);
		$$(container).addClass('features-js');
		
		if ( ! this.options.width) {
			this.options.width = this.features[0].getSize().x;
		}
		
		this.features.each(function(feature, index){
			feature.setStyle('left', (index*this.options.width)+'px');
		},this);
		
		
		$$(this.options.next).addEvent('click', function(e) { this.move(e,1)}.bind(this));
		$$(this.options.prev).addEvent('click', function(e) { this.move(e,-1)}.bind(this));
	},
	move: function(e,direction) {
		e.stop();
		// prevent massive build of up unending clicks
		if (this.waiting_clicks > this.options.max_clicks) {
			return false;
		}
		this.waiting_clicks++;

		if (this.features[this.current_pos + direction]) {
			// note unable to chain different tween animations in the this manner
			this.belt.set('tween', {duration: 800, link: 'chain', onComplete: this.reduce_clicks.bind(this)});
			this.belt.tween('left', (-(this.current_pos+direction)*this.options.width)+'px');
			this.current_pos += direction;
		} else {
			var pos = direction > 0 ? 0 : this.options.width*(this.features.length-1);
			this.belt.set('tween', {duration: 1000, link: 'chain', transition: Fx.Transitions.Back.easeIn, onComplete: this.reduce_clicks.bind(this)});
			this.belt.tween('left', -pos+'px');
			this.current_pos = direction > 0 ? 0 : this.features.length-1;
		}
	},
	reduce_clicks: function() {
		this.waiting_clicks--;
	}
});
