var slideJC = new Class({
	Implements: [Options, Events],
	
	getOptions: function(){
		return {
			box: false,
			duration: 400,
			showItems: 1,
			classItems: 'item',
			autoComplete: true,
			infinite: true,
			leftAct: 0
		};
	},
	initialize: function(options){
		this.setOptions(this.getOptions(), options);
		if ( !this.options.box ) return false;
		
		this.items = this.options.box.getElements('.'+this.options.classItems);
		
		if ( this.items.length <= 0 ) return false;
		
		this.itemSize = this.items[0].getSize().x;
		
		if ( this.options.autoComplete ) {
			var res = this.items.length % this.options.showItems;
			if ( res > 0 ) {
				var faltan = this.options.showItems - res;
				for ( var i = 0; i < faltan; i++ ) {
					var it_clone = this.items[i].clone();
					this.items.include(it_clone);
					it_clone.inject(this.options.box);
				}
			}
		}
		
		if ( this.options.infinite ) {
			this.items.each(function(item) {
				var it_clone = item.clone();
				this.items.include(it_clone);
				it_clone.inject(this.options.box);
			}.bind(this));
		}
		this.options.box.setStyle('width', ( this.itemSize * this.items.length )+'px');
		
		this.itemsShowSize = this.options.showItems * this.itemSize;
		
		this.total = (this.items.length / this.options.showItems).round(0);
		
		this.current = 0;
		
		/*this.fx = new Fx.Tween(this.options.box, {
			property: 'left',
			duration: this.options.duration,
			wait: false
		});*/
		this.fx = new Fx.Morph(this.options.box, {
			duration: this.options.duration,
			wait: false
		});
	},
	previous: function(){
		if ( this.options.infinite ) {
			if ( this.current > 0 ) {
				this.walk(this.current - 1);
			} else {
				this.current = ( this.total / 2 );
				this.options.box.setStyle('left', ( this.itemsShowSize*-this.current )+'px');
				//console.log(( this.itemsShowSize*-this.current )+'px');
				this.walk(this.current - 1);
			}
		} else {
			this.walk(((this.current > 0) ? this.current-1 : this.total-1));
		}
	},

	next: function(){
		
		if ( this.options.infinite ) {
			if ( this.current < (this.total - 1) ) {
				this.walk(this.current + 1);
			} else {
				this.current = ( this.total / 2 ) - 1;
				this.options.box.setStyle('left', ( this.itemsShowSize*-this.current )+'px');
				this.walk(this.current + 1);
			}
		} else {
			this.walk(((this.current < (this.total - 1)) ? (this.current + 1) : 0));
		}
	},
	walk: function(item){
		//console.log(item);
		this.current = item;
		//console.log(item);
		//this.currentIndex = item;
		if ( this.fx )
			this.fx.cancel();
		
		var to =  this.itemsShowSize*-this.current;
		//this.fx.start( to );*/
		//this.fx.start(this.itemsShowSize*-this.current);
		this.fx.start({
			'left':[ this.options.leftAct, to],
			'opacity':[0.5,1]
		});
		this.options.leftAct = to;
	}
	
});