function SLIDESHOW(objSelf)
{ 
   this.objSELF = objSelf;

   this.objEffect = new EFFECTS();

   this.URLScript  = "";
   this.arrOpacity = [0,100];

   this.arrPhotos     = Array();
   this.cntPhotos     = 0;
   this.idxLoaded     = 0;
   this.idxPhotoCurr  = 1;
   this.idxTransition = 1;
   
   this.IDSlideshow = "slideshow";
   this.IDPhoto     = "Photo";
   this.IDImage     = "Image";
   this.IDLoader    = "Loader";
   this.IDProgress  = "Progress";
   this.IDTitle     = "Title";
   this.IDShape     = "Shape";

   this.LoaderStatus = 0;
   this.arrOffset    = [15, 15];

   this.DelaySlide   = 5000;
   this.DelayProcess = 100;

   this.HandlerSwitch  = null;
   this.HandlerProcess = null;

   this.isSwitchEnabled = false;

   //+---

   this.Start = function()
     {
        clearInterval(this.HandlerSwitch);
        this.HandlerSwitch = setInterval(this.objSELF+".SwitchToNext()", this.DelaySlide);
     }

   //+---

   this.SwitchToNext = function()
     {
        var idxNext     = ((this.idxPhotoCurr == this.cntPhotos) ? 1 : this.idxPhotoCurr+1); 
        var IDPhotoCurr = this.IDPhoto+this.idxPhotoCurr;
        var IDPhotoNext = this.IDPhoto+idxNext;
        var IDImageNext = this.IDImage+idxNext;

        switch (this.objEffect.Type)
          {
             case this.objEffect.FADE:
               this.objEffect.Fade(IDPhotoCurr, IDPhotoNext, true);
             break; 

             case this.objEffect.SLIDE:
               this.objEffect.Slide(IDPhotoCurr, IDPhotoNext, false, 0, true); 
             break; 

             case this.objEffect.BARN:
               this.objEffect.Barn(IDPhotoCurr, IDPhotoNext, IDImageNext, false, 0, true); 
             break; 
          }

        if (this.idxPhotoCurr < this.cntPhotos)
               this.idxPhotoCurr++;
          else this.idxPhotoCurr = 1;
     }

   //+---

   this.PhotoLoading = function()
     {
        this.idxLoaded++;

        var IDPhoto  = this.IDPhoto+this.idxLoaded;
        var IDImage  = this.IDImage+this.idxLoaded;

        var objImage = objCore.GetObjectByID(IDImage);
        objImage.src = this.URLScript+this.arrPhotos[IDPhoto]["ID"]+"&"+this.GetHash();
     }

   //+---

   this.SetLoader = function()
     {            
        var IDPhoto = this.IDPhoto+this.idxLoaded;   
        var Percent = ((this.idxLoaded == this.cntPhotos) ? 1 : this.arrPhotos[IDPhoto]["STATUS"]);

        this.LoaderStatus+= Percent;

        var objProgress = objCore.GetObjectByID(this.IDProgress);
        objProgress.innerHTML = Math.ceil(this.LoaderStatus*100);
     
        if (this.idxLoaded == this.cntPhotos)
          objCore.BlockHide(this.IDLoader); 
     }

   //+---

   this.SetLoaded = function(idxPhoto)
     {
        var IDPhoto = this.IDPhoto+this.idxLoaded; 
        this.arrPhotos[IDPhoto]["LOADED"] = true;

        this.SetLoader(); 

        if (this.idxLoaded == 1)
          {
             this.objEffect.FadeSingle(this.IDPhoto+this.idxLoaded, false, true, null, true);

             if (this.cntPhotos > 1)
               this.HandlerSwitch = setTimeout(this.objSELF+".SetSwitchEnabled()", this.DelaySlide);
          }

        if (this.idxLoaded < this.cntPhotos)
          this.PhotoLoading();
     }

   //+---

   this.IsAllLoaded = function()
     {
        var cntLoaded = 0;

        for (i=0; i < this.arrPhotos.length; i++)
          if (this.arrPhotos[this.IDPhoto+(i+1)]["LOADED"])
            cntLoded++;

        return (cntLoded == this.cntPhotos);
     }

   //+---

   this.SetSwitchEnabled = function()
     {
        this.isSwitchEnabled = true;
     }

   //+---

   this.ProcessHandler = function()
     {    
        if (!this.isSwitchEnabled) return;

        if (this.idxTransition < this.cntPhotos)
          {
             var IDPhotoCurr = this.IDPhoto+this.idxTransition;
             var IDPhotoNext = this.IDPhoto+(this.idxTransition+1);

             if (this.arrPhotos[IDPhotoCurr]["TRANSITION"] && this.arrPhotos[IDPhotoNext]["LOADED"])
               {
                  this.idxTransition++;
                  this.SwitchToNext();

                  this.isSwitchEnabled = false;
                  this.HandlerSwitch = setTimeout(this.objSELF+".SetSwitchEnabled()", this.DelaySlide);
               }
          }
          else 
          {
             this.Start();
             clearInterval(this.HandlerProcess);
          }
     }

   //+---

   this.Init = function(URLScript, arrPhotos, recEffect)
     {
        this.URLScript = URLScript;
        this.cntPhotos = arrPhotos.length;

        for (i=0; i < arrPhotos.length; i++)
          {
             var arrPhoto = new Array();
              
             arrPhoto["ID"]      = arrPhotos[i][0];
             arrPhoto["FOLDER"]  = arrPhotos[i][1];
             arrPhoto["NAME"]    = arrPhotos[i][2];
             arrPhoto["EVENT"]   = arrPhotos[i][3];
             arrPhoto["STATUS"]  = arrPhotos[i][4];

             arrPhoto["LOADED"]     = false;
             arrPhoto["IMAGE"]      = new Image();
             arrPhoto["OPACITY"]    = 0;
             arrPhoto["HANDLER"]    = null;
             arrPhoto["TRANSITION"] = false;
 
             var IDPhoto = this.IDPhoto+(i+1);
             this.arrPhotos[IDPhoto] = arrPhoto;
          }

        objCore.BlockShow(this.IDLoader);
        objCore.SetBlockSize(this.IDTitle, this.IDShape);

        var objProgress = objCore.GetObjectByID(this.IDProgress);
        objProgress.innerHTML = 0;
        
        this.objEffect.Init(this.objSELF+".objEffect", this, {"Type":recEffect[0], "Speed":recEffect[1]}, 
                            [this.arrOpacity[0],this.arrOpacity[1]]);

        this.HandlerProcess = setInterval(this.objSELF+".ProcessHandler()", this.DelayProcess);

        this.PhotoLoading();
     }

   //+---

   this.GetRandomInt = function(Min, Max)
     {
        return Math.floor(Math.random()*(Max-Min+1))+Min;
     }

   //+---

   this.GetHash = function()
     {
        var Hash  = "";
        var Chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";

        for (i=0; i < 32; i++)
          Hash+= Chars.charAt(this.GetRandomInt(1, Chars.length)-1);

        return Hash;
     }
}

var objSlideshow = new SLIDESHOW("objSlideshow");