/**
 *  DIAPORAMA
 */
	/** PARAMETERS **/
	var effect = 1;
	var time = 6000;
	
	var current_image = 0;
	var next_image = 1;
	var image = new Array();
	var timer;
	
	/****************/
	
	/**
	 * Init the diaporam
	 * 
	 * @param class name of the img markup
	 * @param random Boolean definit si la premiere img et prise aleatoirement
	 */
	function init_diaporama(class_name,random,time_display) {
		if(document.getElementsByClassName(class_name)) {
			image = document.getElementsByClassName(class_name);
			for(i=1; i < image.length; i++) {
				image[i].style.display = "none";
			}
		}
		
		if( time_display ){
			time = time_display;
		}
		
		if( random ){
			next_image = Math.ceil(Math.random() * (image.length-1));
		}
		
		if(image.length > 1) galerie();
	}
	
	/**
	 * Auto diaporama
	 */
	function galerie() {
		timer = self.setTimeout("nextimage(true)",time);	
	}
	
	/**
	 * Display the next picture
	 * 
	 * @param play boolean to stop  or play the diaporamo (manuel mode)
	 */
	function nextimage(play) {
		if(effect == 1) { new Effect.Fade(image[current_image]); new Effect.Appear(image[next_image]); }
		if(effect == 2) { new Effect.BlindUp(image[current_image]); new Effect.BlindDown(image[next_image]); }
		
		if(next_image == (image.length-1)) {
			current_image = next_image;
			next_image = 0;
		} else {
			current_image = next_image;
			next_image++;
		}
		
		if( play ){
			galerie();
		}else{
			if( timer ){
				self.clearTimeout(timer);
			}
		}
	}
	
	/**
	 * Display the previous picture
	 * 
	 * @param stop boolean stop to stop the diaporamo (manuel mode)
	 */
	function previousimage(play) {
		if(next_image == 0 ) {
			current_image = 0;
			next_image = image.length-1;
		}else{
			current_image = next_image;
			next_image--;
		}
		
		if(effect == 1) { new Effect.Fade(image[current_image]); new Effect.Appear(image[next_image]); }
		if(effect == 2) { new Effect.BlindUp(image[current_image]); new Effect.BlindDown(image[next_image]); }
		
				
		if( play ){
			galerie();
		}else{
			if( timer ){
				self.clearTimeout(timer);
			}
		}
	}