function getSlideShowData( src, link, title, description, width, height ){
		//							0,		1, 		2, 		3, 						4, 			5
		return new Array(src, link,	title, description, width, height);
		
}

// declaring the class
var timedSlideShow = new Class({  

		setOptions: function(options){
			this.options = {
				transitionStart: Fx.Transitions.sineInOut,
				transitionEnd: Fx.Transitions.sineInOut,
				fxDuration: 400,
				initialHeight: 400,
				initialWidth:870,
				delay:5000,
				data: Array(),
				container:"",
				slideInfoZone:"",
				showInfoZone:1,
				startIndex:0,
				enabled:1,
				autoplay:1,
				onShowImage:function(){},
				className: 'slideElement'
			}
			Object.extend(this.options, options || {});
		},

		initialize: function(element, options) {
					
			this.setOptions(options);
			this.onShowImage = this.options.onShowImage;
			this.lastElement = null;
			this.currentElement = null;		
			this.maxIter = this.options.data.length;
			this.lastIter = null;
			this.currentIter = this.options.startIndex;
			this.enabled = this.options.enabled;
			// si la liste des images est inférieur ou égale à 1 ... alors pas de slideshow
			if (this.options.data.length <= 1) this.enabled = 0;
			// Elements initialisation
			element = $(element);
			this.slideShowElement = element;
			element.style.display="block";
			element.style.height=this.options.initialHeight+"px";
			
			this.container = document.createElement('div');
			this.container.className = 'global';
			this.container.id = 'slideshowContainer';
			//this.container.href = this.options.container;	
			element.appendChild(this.container);					

			if (this.options.showInfoZone){
				this.slideInfoZone = document.createElement('div');
				this.slideInfoZone.className = 'slideInfoZone';
				this.slideInfoZone.style.opacity = 0;
				this.slideInfoZone.style.position = "relative";
				this.slideInfoZone.styles = new fx.Styles(this.slideInfoZone);
				this.slideInfoZone.setStyle('opacity', 0);			
				this.slideInfoZone.setStyle('z-index', 3333);
				this.container.appendChild(this.slideInfoZone);
			}
			this.doSlideShow();
		},
		play: function(){
			this.enabled = 1;
			this.next();
		},
		stop: function(){
			this.enabled = 0;
			clearInterval(this.interval);
			clearTimeout(this.timeShowInfo);			
		},
		next:function(){
			this.lastIter = this.currentIter;
			this.currentIter++;
			if (this.currentIter >= this.maxIter)
			{
				this.currentIter = 0;
				this.lastIter = this.maxIter - 1;
			}
			this.doSlideShow.bind(this)();
			
		},
		previous:function(){
			this.lastIter = this.currentIter;
			this.currentIter--;
			if (this.currentIter < 0)
			{
				this.currentIter = this.maxIter-1;
				this.lastIter = 0;
			}
			this.doSlideShow.bind(this)();			
		},
		doSlideShow: function() {
			clearInterval(this.interval);
			clearTimeout(this.timeShowInfo);
			clearTimeout(this.timeHideInfo);			
			this.loadNextImage();
		},
	
		// Charge le fichier source de la prochaine image
		loadNextImage:function(){			
			var i = this.currentIter;
			var src = this.options.data[i][0];
			var obj = this;	
			
			if ( src.substr(src.length-3, 3) == 'swf' ){
				var currentImg 						= document.createElement('div');
				this.lastElement = this.currentElement;
				this.currentElement = currentImg;		
									
				currentImg.className 			= this.options.className;					
				currentImg.innerHTML = this.getFlashHTML(src, "swf"+i,  this.options.initialWidth,  this.options.initialHeight);
				currentImg.style.position = "absolute";
				currentImg.style.width = this.options.initialWidth+'px';
				currentImg.style.height = this.options.initialHeight+'px';
				currentImg.id =  "img"+i;
				
				this.slideShowElement.style.height = this.options.initialHeight+"px";	
				this.onNextImageLoaded(this.options.delay*2);
				
			} else {
				var currentImg 						= document.createElement('img');				
				this.lastElement = this.currentElement;
				this.currentElement = currentImg;
				
				currentImg.className 			= this.options.className;
				currentImg.style.position = "absolute";
				currentImg.style.display = "none";
				currentImg.id 						= "img"+i;
				currentImg.src 						= src;
				
				currentImg.onload = function(){
						obj.slideShowElement.style.height=this.height+"px";		
						obj.onNextImageLoaded();
						this.onload = null					
				}
			}
			
		},	
		// image chargée ... -> affiche l'image
		onNextImageLoaded: function(delay) {
			if (delay == undefined){
				delay = this.options.delay;
			}
			this.showImage();
			// intervals pour les infos
			this.timeShowInfo = setTimeout(this.showInfoSlideShow.bind(this),1000);
			this.timeHideInfo = setTimeout(this.hideInfoSlideShow.bind(this),delay-1000);					
			if (this.enabled){					
				// interval pour le prochain fondu
				this.interval = setInterval(this.nextSlideShow.bind(this),delay);
			}
		},
		
		// déclenche le cahrgement de la prochaine image
		nextSlideShow: function() {
			this.lastIter = this.currentIter;
			this.currentIter++;
			if (this.currentIter >= this.maxIter)
			{
				this.currentIter = 0;
				this.lastIter = this.maxIter - 1;
			}
			this.doSlideShow.bind(this)();
		},
		
		// déclenche le chargement d'une image donnée (PUBLIC)
		setCurrent: function(id){
			this.hideInfoSlideShow();	
			this.lastIter = this.currentIter;
			this.currentIter = parseInt(id);
			this.enabled = 0;
			this.doSlideShow.bind(this)();		
		},		
		
		
		showImage: function(){
			
			// image courante
			lastEl = 	this.lastElement;
			el = this.currentElement;
		
			this.container.appendChild(el);										
			
			if (el.nodeName == 'IMG'){
				// fade
				var fade = new Fx.Style(el, 'opacity', {duration: this.options.fxDuration}).set(0);					
				var issafari = navigator.userAgent.indexOf("Safari");
				el.style['z-index'] = 2222;
				el.style.display = "";
				fade.custom(0, 1);
				if (el.width < this.options.initialWidth && issafari==-1 ){ // <- rustine !!!
					el.style.left = '50%';
					el.style.margin = '0 ' + '-' + (el.width/2) + 'px';
				} 
	
				// ancienne image
				if (this.lastIter  != null){
					var obj = this;
					fade.options.onComplete = function() {							
							obj.hideImage();
					}
					lastEl.style['z-index'] = 2221;
				}
				if (this.lastIter  == null){
					this.slideShowElement.style.height =  el.height +'px';
				}									
				//var resize = new fx.Height (this.slideShowElement , {duration: this.options.fxDuration});	
				var resize = new Fx.Style(this.slideShowElement, 'height',{duration:this.options.fxDuration});
				resize.custom(this.slideShowElement.offsetHeight, el.height);							
				
			} else {	
				if (this.lastIter  != null){			
					this.hideImage();				
				}
			}		
			
			this.onShowImage(this.options.data, this.currentIter);
		},
		
		hideImage: function(){			
			var cont = document.getElementById('slideshowContainer');
			var nodetobedeleted = document.getElementById('img'+ this.lastIter);
			if (nodetobedeleted.nodeName == 'DIV'){
				nodetobedeleted.innerHTML = '';
			}
			var oldnode = cont.removeChild( nodetobedeleted );			
		},
			
		
		showInfoSlideShow: function() {
			
			if (this.options.showInfoZone){
				// build zone info
				this.slideInfoZone.innerHTML = '';
				var slideInfoZoneTitle = document.createElement('h3');
				slideInfoZoneTitle.innerHTML = this.options.data[this.currentIter][2]
				this.slideInfoZone.appendChild(slideInfoZoneTitle);
				
				var slideInfoZoneDescription = document.createElement('p');
				slideInfoZoneDescription.innerHTML = this.options.data[this.currentIter][3];			
				this.slideInfoZone.appendChild(slideInfoZoneDescription);
				
				this.container.appendChild(this.slideInfoZone);
				this.container.href = this.options.data[this.currentIter][1];
	
				this.slideInfoZone.setStyle('top', (this.slideShowElement.offsetHeight - this.slideInfoZone.offsetHeight)+'px' );
	
				this.slideInfoZone.styles.custom({'opacity': [0, 0.7], 'height': [0, this.slideInfoZone.getStyle('height', true)]});
			}
		},
		hideInfoSlideShow: function() {
			if (this.options.showInfoZone){
				if (this.slideInfoZone.style.opacity != 0){
					this.slideInfoZone.styles.custom({'opacity': [0.7, 0]});
				}
			}
		},	
		
		
		// PRIVATE 
		getFlashHTML: function(src, id, width, height){
	    var flashNode = "";
	    if (navigator.plugins && navigator.mimeTypes && navigator.mimeTypes.length) { // netscape plugin architecture
	      // if (this.getAttribute("doExpressInstall")) this.addVariable("MMplayerType", "PlugIn");
	      flashNode = '<embed type="application/x-shockwave-flash" src="'+ src +'" width="'+ width +'" height="'+ height +'"';
	      flashNode += ' id="'+ id +'" name="'+ id +'" ';
	      flashNode += ' wmode' +'="opaque" ';
	      flashNode += '/>';
	    } else { // PC IE
	      // if (this.getAttribute("doExpressInstall")) this.addVariable("MMplayerType", "ActiveX");
	      flashNode = '<object id="'+ id +'" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="'+ width +'" height="'+ height +'">';
	      flashNode += '<param name="movie" value="'+ src +'" />';
	  		flashNode += '<param name="wmode" value="opaque" />';
				//	flashNode += '<param name="flashvars" value="'+ pairs +'" />';
	      flashNode += "</object>";
	    }
	    return flashNode;
		},
		
		
		destroySlideShow: function(element) {
			var myClassName = element.className;
			var newElement = document.createElement('div');
			newElement.className = myClassName;
			element.parentNode.replaceChild(newElement, element);
		}
});



function initTimedSlideShow(element, data) {
	var slideshow = new timedSlideShow(element, data);
}
	
function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}		