// JavaScript Document

///////////////////////////
//
// DIAPORAMA
//
///////////////////////////

function diaporama(){
	
	/* création d'une référence vers l'objet courant */
	var obj = this;  
		
	/* Propriétés */
	this.diaporamaTableau = new Array();
	this.preloadImage = new Image();
	
	/* Compteur */
	this.i = 0 ;
	
	/* Id des images */
	this.background_affiche = "" ;
	this.background_masque = "";
	
	/* Opacité de base des calques */
	this.alpha_affiche = 1;
	this.alpha_masque = 0 ;
	
	/* delai et cadence */
	this.delai = 6000 ;
	this.cadence = 100 ;
	
	
	/* Tableau */
	this.insertDiaporama = function ( num , value ){
		this.diaporamaTableau[num] = [value];
		this.preload( value );
	}
	
	this.init = function () {
		/* Calque */
		document.getElementById( this.background_masque ).style.opacity == this.alpha_masque;
		document.getElementById( this.background_affiche ).style.opacity == this.alpha_affiche;
		
		document.getElementById( this.background_affiche ).src = this.diaporamaTableau[0];
		setTimeout( function (){ obj.chgBack(); } , this.delai);
		
		return true;
	}
	
	/* Fondu */
	this.fondu = function (){
		document.getElementById( this.background_masque ).src = this.diaporamaTableau[this.i];
		this.enchaine();
	}
	
	this.enchaine = function (){
		
		if ( this.alpha_masque < 1 ) {
			this.alpha_affiche -= 0.1 ;
			this.alpha_masque += 0.1 ;
			document.getElementById(this.background_masque).style.opacity = this.alpha_masque ;
			document.getElementById(this.background_affiche).style.opacity = this.alpha_affiche ;
			setTimeout( function (){ obj.enchaine() ; } , this.cadence);
		}else{
			this.alpha_affiche = 1 ;
			this.alpha_masque = 0 ;
			
			var tempback = this.background_affiche;
			this.background_affiche = this.background_masque ;
			this.background_masque = tempback ;
			
			setTimeout( function (){ obj.chgBack() ; } , this.delai);
		}
	}			
	
	this.chgBack = function (){
		this.i++;
		if ( this.i <  this.diaporamaTableau.length){
			this.fondu ();
		}else{
			this.i = 0;
			this.fondu ();
		}
	}
	
	/* Preload des images */
	this.preload = function ( value ) {
		this.preloadImage.src = value ; 
	}
	
}
