/**
 * @FileFR » Gestion de la galerie
 */

/**
 * @VarFR gaTableaux Array_of_Diaporama » Tableau de diaporamas
 * @VarEN gaTableaux Array_of_Diaporama » Array of slideshows
 */
var gaGalerie = new Array();

/**
 * @FunctionFR checkGalerieLoading » Vérifie que la galerie est chargé
 */
function checkGalerieLoading( gsId ) // GOTO
{
   imgload = 0;
   for (i=0 ; i<gaGalerie[gsId].images.length ; i++) // Vérifie les images dont le chargement est complet
   {
      if (gaGalerie[gsId].images[i].complete)
      {
         imgload++;
      }
   }
   if(imgload == gaGalerie[gsId].images.length)
   {
		document.getElementById(gsId + '-remplissage-progression').style.width = gaGalerie[gsId].width + 'px';
		document.getElementById(gsId + '-remplissage-progression').style.marginLeft = '0px';
		document.getElementById(gsId + '-chargement-images').style.display = 'none';
		eval(gaGalerie[gsId].fonction);
   }
   else
   {
		var imgtotal = gaGalerie[gsId].infos.length;
		var widthprogression = ( imgload * gaGalerie[gsId].width ) / imgtotal;
		document.getElementById(gsId + '-remplissage-progression').style.width = widthprogression + 'px';
		document.getElementById(gsId + '-remplissage-progression').style.marginLeft = ( (gaGalerie[gsId].width / 2) - ( widthprogression / 2 ) ) + 'px';
      setTimeout("checkGalerieLoading('" + gsId + "')", 10);
   }
}

/**
 * @FunctionFR Galerie » Constructeur de la galerie
 */
function Galerie(asName, init, width)
{
   this.name     = asName;
   this.images   = new Array();
   this.infos    = new Array();
   this.fonction = init;
   this.width    = width;
   
   this.Add = function(asImageUrl, asLinkUrl, anWidth, anHeight, asTitle, anId)
   {
      var index = this.infos.length;
      this.infos[index] = new Array();
      this.infos[index]["image"]  = asImageUrl;
      this.infos[index]["link"]   = asLinkUrl;
      this.infos[index]["width"]  = anWidth;
      this.infos[index]["height"] = anHeight;
      this.infos[index]["title"]  = asTitle;
      this.infos[index]["id"]     = anId;
   }

   this.LoadImages = function( ) // GOTO
   {
      for (var i=0 ; i < this.infos.length ; i++)
      {
         this.images[i]        = new Array();
         this.images[i]        = new Image();
         this.images[i].src    = this.infos[i]["image"];
      }
      checkGalerieLoading(this.name);
   }
	
   gaGalerie[this.name] = this;
}

