var fancyCarousel = new Class({
	Implements: [Options, Events],
	
	options: {
		
	},
	
	initialize: function(wrapper,itemCname,options){
		this.wrapper = $(wrapper);
		this.itemCname = itemCname;
		this.items = this.wrapper.getElements("."+this.itemCname);
		this.nItems = this.items.length;
		this.despl = this.items[0].getStyle('width').toInt();
		this.cMargin = this.wrapper.getStyle('margin-left').toInt();
		this.fx = new Fx.Tween(this.wrapper,{
		  duration: 1250,
		  transition: 'cubic:out',
		  link: 'cancel',
		  onComplete: function(){
		    this.fireEvent('completed',this.cIndex);
		  }.bind(this)
		});
		this.cIndex = 0;
	},
	
	goTo: function(where){
		var jumps = where-this.cIndex;
		var direction;
		if (jumps>0){
		  direction = -1;
		}else if (jumps<0){
		  direction = 1;
		}else{
		  direction = 0;
		}
		if (direction!=0){
		  var despl = (this.despl)*jumps;
		  if (direction>0){
		      despl = Math.abs(despl);
		  }else{
		      despl = despl * -1;
		  }
		  //this._anim(this.wrapper.getStyle('margin-left').toInt()+despl);
		  this.cMargin = this.cMargin + despl;
		  this._anim(this.cMargin);
		  this.cIndex = where;
		  this.fireEvent('started',this.cIndex);
		}
	},
	goNext: function(){
	  this.goTo((this.cIndex+1)%this.nItems);
	},
	_anim: function(despl){
		this.fx.start('margin-left',despl);
	}
});
