function EngineSlideShow() {
	
	this.idElements = [],
	this.idElements["forward"] = [],
	this.idElements["backward"] = [],
	this.elements = [],
	this.elements["forward"] = [],
	this.elements["backward"] = [],
	
	this.nbElements = 0, //Le nombre d'elements manipulé
	this.animDuration = 1, //in seconde - duré de l'effet
	this.delay = 5000, // in milliseconde - délais avant changement
	
	this.isRunning = false; // Singelton (pour éviter de lancer deux fois le slide)
	
	this.ctlExecStartTask = null, // Pour la gestion du singelton (gestion des on mouseover / mouseout) qui sont envoyé beaucoup de fois au meme moment
	this.ctlExecStopTask = null,
	this.ctlExecStartTaskInterval = 250, //en millisec //250
	this.ctlExecStopTaskInterval = 500, //en millisec //500
	
	this.task = ["obj", "task"],	// Pour géré stop / start
	
	this.currentSlideIndex = 0,	// L'index des elements qui est utiliser pour le masquage / démasquage
	this.counter = 0,	// apres un "start", le conteur du nombre d'itération auto
	
	this.isForward = true, //true > avance | face > recule
	
	this.slideShow = function(isForward) {
		this.isForward = isForward;
	},
	
	this.setCurrentSlideIndex = function(currentSlideIndex)
	{
		this.currentSlideIndex = currentSlideIndex;
	},

	this.getCurrentSlideIndex = function()
	{
		return this.currentSlideIndex;
	},

	this.setIsForward = function(isForward)
	{
		this.isForward = isForward;
	},

	this.getIsForward = function()
	{
		return this.isForward;
	},
	
	this.removeAllElement = function() {
		this.idElements["forward"] = [];
		this.idElements["backward"] = [];
		this.elements["forward"] = [];
		this.elements["backward"] = [];
		this.nbElements = 0;
	},
	
	this.reDraw = function(idShow) {
		for(var i = 0 ; i < this.nbElements ; i++)
		{
			if (this.idElements["forward"][i] == idShow && this.isForward)
			{
				this.elements["forward"][i].show();
				this.elements["backward"][(this.nbElements - i) - 1].show();
			}
			else if(this.idElements["backward"][i] == idShow && !this.isForward)
			{
				this.elements["forward"][(this.nbElements - i)].show();
				this.elements["backward"][i].show();
			}
			else
			{
				this.elements["forward"][i].hide();
				this.elements["backward"][i].hide();
			}
		}
	},
	
	this.showSlide = function(idSlide)
	{
		var forwardBackward = "forward";
		if(!this.isForward)
		{
			forwardBackward = "backward";
		}
		
		if(this.idElements[forwardBackward])
		{
			var indexSlide = this.idElements[forwardBackward].indexOf(idSlide);
			
			if(this.idElements[forwardBackward][indexSlide])
			{
				this.elements[forwardBackward][indexSlide].show();
			}
		}
	},

	this.hideSlide = function(idSlide)
	{
		var forwardBackward = "forward";
		if(!this.isForward)
		{
			forwardBackward = "backward";
		}
		
		if (this.idElements[forwardBackward])
		{
			var indexSlide = this.idElements[forwardBackward].indexOf(idSlide);
			
			if(this.elements[forwardBackward][indexSlide])
			{
				this.elements[forwardBackward][indexSlide].hide();
			}
		}
	},
	
	this.addElement = function(idElement) {
		
		var element = document.getElementById(idElement);
		element.show = function() {
			YAHOO.util.Dom.setStyle(this, "opacity", 1);
			YAHOO.util.Dom.setStyle(this, "visibility", "visible");
		};
		element.hide = function() {
			YAHOO.util.Dom.setStyle(this, "opacity", 0);
			YAHOO.util.Dom.setStyle(this, "visibility", "visible");
		};
		element.isVisible = function() {
			var opacity = YAHOO.util.Dom.getStyle(this, "opacity");
			if(opacity == 0)
			{
				return false;
			}
			else
			{
				return true;
			}
		};
		
		
		
		if (!element)
		{
			return false;
		}
		
		this.nbElements++;
		element.hide();
		
		// >>
		this.idElements["forward"].push(idElement); 
		this.elements["forward"].push(element);

		// <<
		this.idElements["backward"] = this.idElements["forward"].slice();
		this.elements["backward"] = this.elements["forward"].slice();
		this.idElements["backward"].reverse();
		this.elements["backward"].reverse();
		
		return true;
	},
	
	// in milliseconde
	this.setDelay = function(delay) {
		this.delay = delay;
	},

	this.startDelayed = function(isExecImmediately, isBackward) {
	
		//alert('startDelayed');
		if(this.ctlExecStartTask)
		{
			this.ctlExecStartTask.cancel();
		}

		this.ctlExecStartTask = YAHOO.lang.later(this.ctlExecStartTaskInterval, this, 'startstartDelayedRun', [isExecImmediately, isBackward], false);
	},
	
	this.stopDelayed = function() {
	
		//alert('stopDelayed');
		if(this.ctlExecStartTask)
		{
			this.ctlExecStartTask.cancel();
		}
		if(this.ctlExecStopTask)
		{
			this.ctlExecStopTask.cancel();
		}

		this.ctlExecStopTask = YAHOO.lang.later(this.ctlExecStopTaskInterval, this, 'stopDelayedRun', [], false);		
	
	},
	
	this.startstartDelayedRun = function(isExecImmediately, isBackward) {
	
		if(this.ctlExecStopTask)
		{
			this.ctlExecStopTask.cancel();
		}
		
		if(this.ctlExecStartTask)
		{
			this.ctlExecStartTask.cancel();
		}
		
		this.start(isExecImmediately, isBackward);
		
	},

	this.stopDelayedRun = function() {
	
		this.stop();
	
	},
	
	this.start = function(isExecImmediately, isBackward) {
		//alert('start');
		
		if(this.isRunning)
		{
			return true;
		}
		
		this.isRunning = true;
		this.counter = 0;
		if (this.nbElements < 2)
		{
			return false;
		}
		
		execImmediately = false;
		if (isExecImmediately)
		{
			execImmediately = true;
		}
		
		if(isBackward !== undefined)
		{
			previousIsForward = this.isForward;
			this.isForward = true;
			if(isBackward)
			{
				this.isForward = false;
			}
			
			if (previousIsForward != this.isForward)
			{
				this.currentSlideIndex = (this.nbElements - this.currentSlideIndex) - 1;
			}
		}
		
		//alert(execImmediately);
		if (this.currentSlideIndex < 0)
		{
			this.currentSlideIndex = 0;
		}		
		else if (this.currentSlideIndex > this.nbElements)
		{
			this.currentSlideIndex = 0;
		}
		
		if(!this.isForward)
		{
			// Montre le 1er element
			this.elements["backward"][this.currentSlideIndex].show();			
		}
		else
		{
			// Montre le 1er element
			this.elements["forward"][this.currentSlideIndex].show();			
		}
		
		//alert("NbElem: " + this.nbElements + "\nId Img >> Start : " + this.idElements["forward"][0] + "\nId Img << Start : " + this.idElements["backward"][0] + "\nId Img >> End : " + this.idElements["forward"][9] + "\nId Img << End : " + this.idElements["backward"][9]);
		
		// Start a simple clock task that updates a div once per second
		this.task['task'] = {
		    run: this.anim,
		    interval: this.delay,
			scope: this,
			args: [execImmediately]
		}
		
		this.task['obj'] = new Ext.util.TaskRunner();
		this.task['obj'].start(this.task['task']);		
	},
	
	this.stop = function() {
		//alert('stop');
		
		if(!this.isRunning)
		{
			return true;
		}
		
		this.isRunning = false;
		
		if (this.task['obj'])
		{
			this.task['obj'].stop(this.task['task']);
		}
	},
	
	this.previous = function() {
		this.stop();
		this.start(true, true);
	},
	
	this.next = function() {
		this.stop();
		this.start(true, false);	
	},
	
	this.print = function(caractere) {
		if(caractere == undefined) var caractere = '';
		var conteneur=document.getElementById("imgSmall_"+caractere+this.currentSlideIndex).innerHTML;
		var reg=new RegExp('src="(.*?)"','g');
		var link = reg.exec(conteneur);
		var img = link[1].replace('252','800');
		while (img.indexOf('&amp;') != -1){ 
			img = img.replace('&amp;','&');
		}
		img = img.replace('208','600');
		var WindowObject = window.open("", "TrackHistoryData", 
						  "width=800,height=600,top=250left=345,toolbars=no,scrollbars=yes,status=no,resizable=yes");
		WindowObject.document.write('<img src="'+img+'">');
		WindowObject.document.close();
		WindowObject.focus();
		WindowObject.print();
		WindowObject.close();
	},
	this.anim = function() {
		this.counter++;
		
		var isExecImmediately = arguments[0];
		
		if (!isExecImmediately && this.counter == 1)
		{
			//Ne pas faire la 1ere itération
			return true;
		}
		
		if (this.currentSlideIndex < 0)
		{
			this.currentSlideIndex = 0;
		}		
		currentIndex = this.currentSlideIndex;
		this.currentSlideIndex++;
		if ( (this.currentSlideIndex + 1 > this.nbElements))
		{
			this.currentSlideIndex = 0;
		}
		
		nextIndex = this.currentSlideIndex;

		//alert('nbElem: ' + this.nbElements + "\n" + 'currentIndex: ' + currentIndex + "\nnextIndex: " + nextIndex);
		
		if(this.isForward)
		{
			var elemOut = this.elements["forward"][currentIndex];
			var elemIn = this.elements["forward"][nextIndex];
		}
		else
		{
			var elemOut = this.elements["backward"][currentIndex];
			var elemIn = this.elements["backward"][nextIndex];		
		}
		
		var debug = '';
		debug += 'currentIndex: ' + currentIndex + ' - nextIndex: ' + nextIndex + "\n\n";
		for(var i = 0 ; i < this.nbElements ; i++)
		{
			if(!this.isForward)
			{
				debug += '<<< elem: ' + i + ' - ' + this.elements["backward"][i].isVisible() + "\n\n";
			}
			else
			{
				debug += '>>> elem: ' + i + ' - ' + this.elements["forward"][i].isVisible() + "\n\n";
			}
		}
		//alert(debug);
		
		
		var oElemOut = new YAHOO.util.Anim(elemOut, {opacity: {from: 1, to: 0} }, this.animDuration, YAHOO.util.Easing.easeOut);
		var oElemIn = new YAHOO.util.Anim(elemIn, {opacity: {from: 0, to: 1} }, this.animDuration, YAHOO.util.Easing.easeIn);
		//alert(oElemOut);
		oElemOut.animate();
		oElemIn.animate();
	}
};
