var slideJC = new Class({
	Implements: [Options, Events],
	
	getOptions: function(){
		return {
			box: false,
			duration: 400,
			showItems: 1,
			showSlide: 5,
			classItems: 'item',
			autoComplete: true,
			infinite: true
		};
	},
	initialize: function(options){
		this.setOptions(this.getOptions(), options);
		if ( !this.options.box ) return false;
		if ( $$('.'+this.options.classItems).length <= 0 ) return false;
		
		this.items = this.options.box.getElements('.'+this.options.classItems);
		this.itemSize = this.options.box.getElement('.'+this.options.classItems).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);
		//console.log('Total: '+this.items.length);
		//console.log('Ver: '+this.options.showItems);
		//console.log('Round: '+this.total);
		this.current = 0;
		
		this.fx = new Fx.Tween(this.options.box, {
			property: 'left',
			duration: this.options.duration,
			wait: false
		});
	},
	previous: function(manual){
		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.currentIndex == 1 )?-292:0;
		this.fx.start( to );*/
		this.fx.start(this.itemsShowSize*-this.current);
	}
	
});