var ManchetteSwitcher = Class.create();
ManchetteSwitcher.prototype = {
	initialize:function(oConfig)
	{
		//Constructor params
		this._nTotalPic = oConfig.totalPic;
		this._timeToSwitch = oConfig.timeToSwitch;
		this._previousID = oConfig.previousID;
		this._nextID = oConfig.nextID;
		//Object params
		this._nCurrentPic = 1;
		this._nNewPic = 0;
		this._playing = 1;
		this._pe = null;
		//Init calls
		this.jsDisplay();
	},	
	jsDisplay:function()
	{
		if (this._nTotalPic > 1)
		{
			this.setButtons();
			this.play();
		}
	},
	setButtons:function()
	{
		$(this._previousID).observe('click',this.displayNextItem.bindAsEventListener(this,-1,'manual'));
		$(this._nextID).observe('click',this.displayNextItem.bindAsEventListener(this,1,'manual'));
	},
	displayAccroche:function()
	{		
		var accroches = $$('#manchette .articles li');
		var nextSlide = accroches[this._nNewPic-1];
		var currentSlide = accroches[this._nCurrentPic-1];
		//In new
		var fadeSpeed = 10;
		var faderNext = new Fadomatic(nextSlide, fadeSpeed, 0, 0, 100, 1);
		faderNext.fadeIn();
		//Out current
		var faderCurrent = new Fadomatic(currentSlide, fadeSpeed, 100, 0, 100, 1);
		faderCurrent.fadeOut();
	},
	play:function()
	{
		this._pe = new PeriodicalExecuter(this.displayNextItem.bindAsEventListener(this,1),this._timeToSwitch);
		this._playing = 1;
	},
	pause:function()
	{
		this._pe.stop();
		this._playing = 0;		
	},
	displayNextItem:function(e,dir)
	{
		if ($A(arguments).length > 3) { this.pause(); }
		if (dir == 1)
		{
			this._nNewPic = this._nCurrentPic+1;
		}else
		{
			this._nNewPic = this._nCurrentPic-1;
		}
		//Check if below min or above max
		if (this._nNewPic>this._nTotalPic) {
			this._nNewPic=1;
		}
		if (this._nNewPic<1) {
			this._nNewPic=this._nTotalPic;
		}
		//Call display
		this.displayCurrentItem();
	},
	displayCurrentItem:function()
	{
		this.displayAccroche();
		//Update current pic ref for next time
		this._nCurrentPic = this._nNewPic;
		//this.checkPauseSrc();	
	}
}