var slide = new Class({

	initialize: function(params){
		this.items = params.items;
		this.size = 128;
		this.steps = 6;
		this.box = params.box.setStyle('width',(this.size*this.items.length)+'px');
		this.currentIndex = null;
		this.previousIndex = null;
		this.nextIndex = null;
		this._play = null;
		this.buttons = {
			previous: [],
			next: []
		};
		if(params.addButtons){
			for(var action in params.addButtons){
				this.addActionButtons(action, $type(params.addButtons[action])=='array' ? params.addButtons[action] : [params.addButtons[action]]);
			}
		}
		this.fx = new Fx.Tween(this.box,$extend((params.fxOptions||{duration:500,wait:false}),{property:'left'}));
		this.walk((params.startItem||0),true,true);
	},

	addActionButtons: function(action,buttons){
		for(var i=0; i<buttons.length; i++){
			switch(action){
				case 'previous': buttons[i].addEvent('click',this.previous.bind(this,[true])); break;
				case 'next': buttons[i].addEvent('click',this.next.bind(this,[true])); break;
			}
			this.buttons[action].push(buttons[i]);
		}
	},

	previous: function(manual){
		if (this.currentIndex-this.steps<0) {
			this.walk(0,manual);
		} else {
			this.walk(this.currentIndex-this.steps,manual);
		}
	},

	next: function(manual){
		if (this.currentIndex+this.steps>this.items.length-1-this.steps) {
			this.walk(this.items.length-1-this.steps,manual)
		} else {
			this.walk(this.currentIndex+this.steps,manual)
		}
	},

	walk: function(item,manual,noFx){
		if(item!=this.currentIndex){
			this.currentIndex=item;
			this.previousIndex = this.currentIndex + (this.currentIndex>0 ? -1 : this.items.length-1);
			this.nextIndex = this.currentIndex + (this.currentIndex<this.items.length-1 ? 1 : 1-this.items.length);
			if(manual){
				$clear(this._play);
			}
			if(noFx){
				this.fx.cancel().set((this.size*-this.currentIndex)+'px');
			}else{
				this.fx.start(this.size*-this.currentIndex);
			}
		}
	}
	
});