// **************************** //
// Copyright 2005 Streambay LLC //
// All Rights Reserved          //
// **************************** //
function _image(id_name, image_id)
{
   this.opacity   = 0;
   this.id        = document.getElementById(id_name);
   this.image_id  = image_id;
   this.ie = (window.navigator.appName == "Microsoft Internet Explorer") ? true : false;
   
   this.zeroOpacity = function(difference) {this.change_opacity(this.opacity * -1);};
   
   this.get_image_id = function() {return(this.image_id);};
   this.change_opacity = function(difference)
   {
      this.opacity += difference;
      /********the problem with floats...********/
      if (this.opacity > 1) {this.opacity = 1;}
      if (this.opacity < 0) {this.opacity = 0;}
      
      if (this.ie) { this.id.filters.alpha.opacity = this.opacity * 100; }
      else	   { this.id.style.opacity         = this.opacity }
   };
   this.zeroOpacity();
}

function fader(timer, opacities_increment, finished_timer)
{
   this.TIMER               = timer; /* time between ticks for fade  - time for full fade = TIMER/OPACITIES_INCREMENT */
   this.OPACITIES_INCREMENT = opacities_increment;
   this.FINISHED_TIMER      = finished_timer;
   
   this.images              = new Array;
   this.INDEX_MAX           = 0;
   this.LAST_BORDER         = -1;

   this.add                = function(link, image_id)  { this.images.push(new _image(link, image_id));};
   this.stopSlideShow      = 0;

   this.restart_slide_show = function()
   {
      document.getElementById("right_image_" + this.INDEX_MAX).style.border="2px solid #bbb";
      this.INDEX_MAX       = 0;
      this.LAST_BORDER     = -1;
      for (var i = 0; i < this.images.length; i++)
      {
         this.images[i].zeroOpacity();
      }
      this.stopSlideShow = 0;
      this.transition();
   };
   this.stop_slide_show = function(num)
   {
      this.stopSlideShow = 1;
      this.INDEX_MAX     = num;
      this.images[num].change_opacity(1);
      document.imageActionForm.imageid.value = this.images[num].get_image_id();
      document.imageActionForm.image_location.value = num;
      for (var i = 0; i < this.images.length; i++)
      {
         if (i != num) {this.images[i].zeroOpacity();}
      }
      this.change_border();
   };   
   
   this.change_border = function()
   {
      var right_image = document.getElementById("right_image_" + this.LAST_BORDER);
      var right_image2 = document.getElementById("right_image_" + this.INDEX_MAX);
      if (! right_image || !right_image2) {return;}
      if (this.LAST_BORDER >= 0)
      {
	right_image.style.border="2px solid #bbb";
      }
      right_image2.style.border="2px solid yellow";
      this.LAST_BORDER = this.INDEX_MAX;
   };                                        
   this.transition = function(new_image)
   {
      if (this.LAST_BORDER < 0 || new_image) {this.change_border();}
   
      if (this.stopSlideShow) { return(0); }
      if (this.images[this.INDEX_MAX].opacity >= 0.95)
      {
         //change opacity
         if (this.INDEX_MAX == this.images.length - 1)   { this.INDEX_MAX = 0; }
         else                                            { this.INDEX_MAX++;   }
         
         return(setTimeout("f.transition(1);", this.FINISHED_TIMER));
      }
      for (var i = 0; i < this.images.length; i++)
      { 
         if (i == this.INDEX_MAX) {
            this.images[i].change_opacity(this.OPACITIES_INCREMENT);
         }
         else {
            if (this.images[i].opacity > 0)
            {
               this.images[i].change_opacity(-1 * this.OPACITIES_INCREMENT);
            }
         }
      }
      setTimeout("f.transition();", this.TIMER);
   };
}

