var mooRoquetteSlidingTabs = new Class ({

	Implements: [Events, Options],

	options: {
		onNext      : Class.empty,
		onPrev      : Class.empty,
		onStart     : Class.empty,
		transition  : Fx.Transitions.linear,
		duration    : 500,
		auto        : false,
		mode        : 'butts',
		mousePlay   : false,
		progressBy  : 1,
		butts       : {
			nextB   : 'edito-navigation-next',
			prevB   : 'edito-navigation-previous'
		},
		items       : {
			space   : 2,
			width   : 105,
			height  : 25
		}
	},

	initialize: function(ziCarrousel, ziItemConteneur, ziItems, options) {
		this.setOptions(options);
		this.carrou   = $(ziCarrousel);
		this.defil    = $(ziItemConteneur);
		this.items    = $$('.' + ziItems) || [];
		this.itemsNum = this.items.length;
		this.itemsRW  = this.options.items.width + this.options.items.space;
		this.itemsRH  = this.options.items.height + this.options.items.space;
		this.sectionW = this.itemsNum * this.itemsRW;
		this.sectionH = this.itemsNum * this.itemsRH;
		this.dn       = this.options.progressBy;
		this.progress = this.options.direction == this.itemsRW * this.dn;
		this.displayedItems = parseInt(this.carrou.getSize().x / this.itemsRW);

		this.defil.setStyles({
			'width'    : this.sectionW,
			'position' : 'absolute',
			'left'     : 0
		});

		if (this.options.mode == "butts") {
			$(this.options.butts.nextB).addEvent('click', function(e){
				e.stop();
				this.toNext();
			}.bind(this));
			$(this.options.butts.prevB).addEvent('click', function(e){
				e.stop();
				this.toPrev();
			}.bind(this));
		}
		
		this.count = 0;
		
		$(this.options.butts.prevB).setStyle('visibility', 'hidden');
		$(this.options.butts.nextB).setStyle('visibility', this.count + this.displayedItems < this.itemsNum ? 'visible' : 'hidden');
		
		this.fireEvent('onStart');
		this.defilFx = new Fx.Morph(this.defil, {
			transition : this.options.transition,
			duration   : this.options.duration,
			link       : 'chain'
		});
		this.count = 0;
	},

	toNext: function() {
		this.compEvent = function(){ this.fireEvent('onNext'); }
		this.count += this.dn;
		this.defilFx.start({'left': -(this.count * this.itemsRW)});
		$(this.options.butts.nextB).setStyle('visibility', this.count + this.displayedItems < this.itemsNum ? 'visible' : 'hidden');
		$(this.options.butts.prevB).setStyle('visibility', this.count > 0 ? 'visible' : 'hidden');
	},

	toPrev: function(){
		this.count -= this.dn;
		this.compEvent = function(){ this.fireEvent('onPrev'); }
		this.defilFx.start({'left': -(this.count * this.itemsRW)});
		$(this.options.butts.nextB).setStyle('visibility', this.count + this.displayedItems < this.itemsNum ? 'visible' : 'hidden');
		$(this.options.butts.prevB).setStyle('visibility', this.count > 0 ? 'visible' : 'hidden');
	}

});
