function PHOTOALBUM(objSELF)
{
   this.objSELF = objSELF;

   this.objEffectPreview = new EFFECTS();
   this.objEffectPhoto   = new EFFECTS();

   this.arrOpacityPhoto   = [0, 100];
   this.arrOpacityPreview = [60, 100];

   this.Speed = 0;

   this.cntPreview     = 0;
   this.idxPreviewCurr = 0;
   this.URLWebsite     = "";

   this.IDFilm     = "Film";
   this.IDScroller = "Scroller";
   this.IDPreview  = "Preview";
   this.IDPhoto    = "Photo";
   this.IDLoader   = "Loader";
   this.IDTitle    = "Title";
   this.IDShape    = "Shape";
   this.IDButtPrev = "ButtonPrev";
   this.IDButtNext = "ButtonNext";
   
   this.arrPhotos       = Array();
   this.IDPreviewOver   = "";
   this.cntPreviewFrame = 6;
   this.idxPreviewStart = 0;

   this.HandlerScroll = null;
   this.DelayScroll   = 0;
   this.isScrolling   = false;
   this.ScrollerXo    = 0;
   this.ScrollWidth   = 734+10;
   this.StepX         = 8;

   //
   // preview
   //

   //+---

   this.PreviewOver = function(BlockID)
     {
        if (this.isScrolling) return;

        this.arrPhotos[BlockID]["ISOVER"] = true;
        this.IDPreviewOver = BlockID;

        clearTimeout(this.arrPhotos[BlockID]["HANDLER"]);
        this.objEffectPreview.FadeSingle(BlockID, false);
     }

   //+---

   this.PreviewOut = function(BlockID)
     {
        clearTimeout(this.arrPhotos[BlockID]["HANDLER"]);
        this.objEffectPreview.FadeSingle(BlockID, true);
     }

   //
   // scrolling
   //

   this.SetScrollStart = function()   
     {
        var idxPage     = Math.floor((this.idxPreviewCurr-1)/this.cntPreviewFrame);
        this.ScrollerXo = -this.ScrollWidth*idxPage;

        this.idxPreviewStart+= idxPage*this.cntPreviewFrame;

        this.SetScroll(this.ScrollerXo);
     }

   //+---

   this.SetScroll = function(X)
     {
        var objScroller = objCore.GetObjectByID(this.IDScroller);
        objScroller.style.left = X+"px";
     }

   //+---

   this.ScrollFilm = function(isToRight, X)
     {
        var objScroller = objCore.GetObjectByID(this.IDScroller);
        var Direction   = ((isToRight) ? -1 : 1);

        if (X == undefined) 
          X = objScroller.offsetLeft;

        this.SetScroll(X);

        if (Math.abs(this.ScrollerXo-objScroller.offsetLeft) < this.ScrollWidth)
          { 
             X+= Direction*this.StepX;

             var Func = this.objSELF+'.ScrollFilm('+isToRight+','+X+')';
             this.HandlerScroll = setTimeout(Func, this.DelayScroll);
          }
          else 
          {
             clearTimeout(this.HandlerScroll);

             this.isScrolling = false;
             this.ScrollerXo  = objScroller.offsetLeft;
          }
     }

   //+---

   this.ScrollToLeft = function()
     {
        if (!this.isScrolling && this.IsCanToLeft())
          {
             this.isScrolling = true;

             this.SetControlButton(false, true);
             this.ScrollFilm(false);
          }
     }

   //+---

   this.ScrollToRight = function()
     {
        if (!this.isScrolling && this.IsCanToRight())
          {
             this.isScrolling = true;

             this.SetControlButton(true, true);
             this.ScrollFilm(true);
          }
     }

   //
   // control
   //

   this.IsCanToLeft = function()
     {
        return (this.idxPreviewStart > 1);
     }

   //+---

   this.IsCanToRight = function()
     {
        return (this.idxPreviewStart+this.cntPreviewFrame < this.cntPreview);
     }

   //+---

   this.ButtonOver = function(isButtLeft, isOver)
     {
        if ((isButtLeft && !this.IsCanToLeft()) || 
            (!isButtLeft && !this.IsCanToRight())) 
          return;

        var ButtonID  = ((isButtLeft) ? this.IDButtPrev : this.IDButtNext);
        var objButton = objCore.GetObjectByID(ButtonID);
        var ImageFile = this.URLWebsite+"b_"+((isButtLeft) ? "prev" : "next")+((isOver) ? "_over" : "")+".gif";

        objButton.src = ImageFile;
     }

   //+---

   this.ControlEnable = function(isButtLeft, isEnable)
     {
        var ButtonID  = ((isButtLeft) ? this.IDButtPrev : this.IDButtNext);
        var objButton = objCore.GetObjectByID(ButtonID);
        var ImageFile = this.URLWebsite+"b_"+((isButtLeft) ? "prev" : "next")+((isEnable) ? "" : "_disabled")+".gif";

        objButton.style.cursor = ((isEnable) ? "pointer" : "default");
        objButton.src = ImageFile;
     }

   //+---

   this.SetControlButton = function(isToRight, isOffset)
     {
        if (isOffset)
          {
             var Direction = ((isToRight) ? 1 : -1);
             this.idxPreviewStart+= Direction*this.cntPreviewFrame;
          }

        this.ControlEnable(true, this.IsCanToLeft());
        this.ControlEnable(false, this.IsCanToRight());      
     }

   //+---

   this.SetControl = function()
     { 
        this.SetControlButton(true); 
        this.SetControlButton(false);
     }

   //+---

   this.ButtPrevOver = function()
     {
        this.ButtonOver(true, true);
     }

   //+---

   this.ButtPrevOut = function()
     {
        this.ButtonOver(true, false);
     }

   //+---

   this.ButtNextOver = function()
     {
        this.ButtonOver(false, true);
     }

   //+---

   this.ButtNextOut = function()
     {
        this.ButtonOver(false, false);
     }

   //+---

   this.Init = function(URLWebsite, cntPreview, idxPreviewCurr, arrEffect)
     {
        this.URLWebsite     = URLWebsite;
        this.cntPreview     = cntPreview;
        this.idxPreviewCurr = idxPreviewCurr;
        this.Speed          = arrEffect[1];

        for (i=1; i <= this.cntPreview; i++)
          {
             var arrPhoto = Array();

             arrPhoto["HANDLER"] = null;
             arrPhoto["OPACITY"] = ((i == this.idxPreviewCurr) ? this.arrOpacityPreview[1] : this.arrOpacityPreview[0]);
             arrPhoto["ISOVER"]  = false;

             this.arrPhotos[this.IDPreview+i] = arrPhoto;
          }

        var arrPhoto = Array();
 
        arrPhoto["HANDLER"] = null;
        arrPhoto["OPACITY"] = 0;
        arrPhoto["ISOVER"]  = false;

        this.arrPhotos[this.IDPhoto] = arrPhoto;

        this.SetScrollStart();
        this.SetControl();

        objCore.BlockShow(this.IDLoader);

        this.objEffectPreview.Init(this.objSELF+".objEffectPreview", this, {"Type":0, "Speed":1}, 
                                   [this.arrOpacityPreview[0],this.arrOpacityPreview[1]]); 
     }

   //
   // photo
   //

   this.PhotoLoaded = function(isTitle)
     {
        objCore.BlockHide(this.IDLoader);

        this.objEffectPhoto.Init(this.objSELF+".objEffectPhoto", this, {"Type":0, "Speed":this.Speed}, 
                                 [this.arrOpacityPhoto[0],this.arrOpacityPhoto[1]]);  

        this.objEffectPhoto.FadeSingle(this.IDPhoto, false, true);

        if (isTitle)
          objCore.SetBlockSize(this.IDTitle, this.IDShape);
     }
}

var objPhotoalbum = new PHOTOALBUM("objPhotoalbum");