var Scroller = new Class({
	initialize: function(container_id, width, item_width, step, prev_id, next_id) {
		
		this.container = $(container_id);
		this.width = width;
		this.step = step;
		this.prev = $(prev_id);
		this.next = $(next_id);
		this.itemsWidth = item_width * this.container.getChildren('.item').length;
		this.pos = 0;
		this.effect = new Fx.Morph(this.container);
		
		this.setActionHandlers();
	}
});

Scroller.implement({
	
	setActionHandlers: function() {
		
		var obj = this;
		
		this.prev.addEvent('click', function(e){
			
			new Event(e).stop();
			obj.goPrev();
		});
		
		this.next.addEvent('click', function(e){
			
			new Event(e).stop();
			obj.goNext();
		});
	},
	
	goPrev: function() {
		
		var new_pos = this.pos + this.step;
		
		if(new_pos > 0) {
			
			new_pos = 0;
		}
		
		this.effect.start({
			left: [this.pos, new_pos]
		});
		
		this.pos = new_pos;
	}, 
	
	goNext: function() {
		
		var new_pos = this.pos - this.step;
		var min_pos = this.width - this.itemsWidth;
		
		if(new_pos < min_pos) {
			
			new_pos = min_pos;
		}
		
		this.effect.start({
			left: [this.pos, new_pos]
		});
		
		this.pos = new_pos;
	}
});

