var fadeSlide = new Class({
	
	Implements: Events,
	
	initialize: function(params){
		this.items = params.items;
		this.size = params.size || 240;
		this.box = params.box;
		this.onWalk = params.onWalk || null;
		this.currentIndex = null;
		this.interval = params.interval || 5000;
		this._play = null;
		this.fadeOut = false;
		this.buttons = {
			next: [],
			stop: []
		};
		
		this.fxOpacity = new Fx.Tween(this.box,$extend({duration:1000,wait:false},{property:'opacity'}));
		this.fxOpacity.addEvent('complete', this.tweenOver.bind(this));
		
		this.step(0);
		this.fxOpacity.start(1);
	},

	tweenOver: function(){
		if (this.fadeOut) {
			this.fadeOut=false;
			this.step((this.currentIndex<this.items.length-1 ? this.currentIndex+1 : 0));
			this.fxOpacity.start(1);
		}
	},
	
	stepFinish: function(){
		this.fadeOut=true;
		this.fxOpacity.start(0);
	},

	step: function(item){
		if (this.currentIndex!=item) {
			this.currentIndex=item;
		
			$clear(this._play);

			this.box.setStyle('top',(-this.size*this.currentIndex)+'px');
//			this.items[this.currentIndex].show();
//			this.items[(this.currentIndex+this.items.length-1)%this.items.length].hide();

			if (this.items.length>1) {this._play=this.stepFinish.periodical(this.interval,this);}
		}
	}
	
	
});
