/*
 * Name:             SlideShow
 *
 * Description:      Displays a slide show
 *
 * Notes:            Requires 'Pic' and 'Cap' arrays be defined in the calling code, Pic be
 *                   stuffed with the name of picture files and Cap with the correspondig
 *                   Captions and this js Module be included. Conclude setup by calling
 *                   loadSlideShow to register the Caps and the Pics.
 *                   Set up a table with an ID of 'ssId', and set a
 *                   'style' setting of 'zoom:1' because MSIE needs it.  In the table,
 *                   set up an 'IMG' with name of 'SlideShow' and a 'SPAN' with an id of 
 *                   'SlideShowCaption'.
 *
 * Author:           Chris Meyer
 *
 * Created:          May, 5, 2009
 * 
 */

function SlideShow(SlideShow_CID)
{
  this.Name         = "o" + (SlideShow_CID).replace(/CID/,"");
  this.Status       = 40;
  this.Item         = 0;
  this.Length       = 0;
  this.Browser      = navigator.appName;
  this.Images       = new Array();
  this.Captions     = new Array();
  this.Image_ID     = 0;
  this.Caption_ID   = 0;
  this.SlideShow_ID = document.getElementById(SlideShow_CID);
  this.loadImages   = loadSlideShowImages;
  this.loadCaptions = loadSlideShowCaptions;
  this.Browser      = navigator.appName;
  this.run          = runSlideShow;
}2

function loadSlideShowImages(Images,Image_CID)
{
  // Get the length of the slideshow
  this.Length = Images.length
  this.Image_ID = document.getElementById(Image_CID);
  this.Item = this.Length - 1;

  for (var i = 0; i < this.Length; i++)
  {
    this.Images[i] = new Image(); 
    this.Images[i].src = Images[i];
  }
}

function loadSlideShowCaptions(Captions,Caption_CID)
{
  // Get the length of the slideshow
  this.Length = Captions.length;
  this.Caption_ID = document.getElementById(Caption_CID);
  this.Item = this.Length - 1;

  for (var i = 0; i < this.Length; i++) { this.Captions[i] = Captions[i]; }
}

// Mode = P (Picture only), C (Caption only) and PC (Both Picture and Caption - default)
function runSlideShow()
{
  var Opacity = 100;
  var Speed = 50;  
  var t;

  if (this.Status == 1)
  {
    this.Item = (this.Item < (this.Length - 1)) ? ++this.Item : 0;
  
    if (this.Caption_ID != 0) 
    { 
      if (typeof this.Captions[this.Item] != "undefined") 
      { this.Caption_ID.innerHTML = this.Captions[this.Item]; }
      else
      { this.Caption_ID.innerHTML = "No Events Scheduled"; }
    }
    if (this.Image_ID != 0 && typeof this.Images[this.Item].src != "undefined") 
    { this.Image_ID.src = this.Images[this.Item].src; }
  }

  Opacity = (this.Status < 21) ? (this.Status * 5) : (100 - (this.Status - 20) * 5);
  Speed = (this.Status == 20) ? 5000 : 50;
  this.Status = (this.Status == 40) ? 1 : ++this.Status;

  if (this.Browser == "Microsoft Internet Explorer")
  { 
    this.SlideShow_ID.style.zoom = '1';
    this.SlideShow_ID.style.filter='alpha(opacity=' + Opacity + ')'; 
  }
  else
  { this.SlideShow_ID.style.opacity = Opacity/100; }

  t = setTimeout(this.Name + ".run()", Speed);
}



