﻿<!--  Hide from non-javascript browsers
//
// Public declarations
//

//
//  Start of object definition for Image Slide Show
//

function imageSlideShow(odata)  
{                                // Constructor for Image Slide Show
   //
   //  Define a instance of function parameter odata
   //
   var CustomData = odata;

   //
   //  Declare 'self' as 'this' so scope doesn't change on us.
   //
   var self = this;
   var timer;
   var showState = "Inactive";
   var previousSlide = -1;

   var picDir = CustomData[0];
   var picArray = CustomData[1];
   var divName = CustomData[2];
   var changeFreq = CustomData[3];
   var numSlideRotations = CustomData[4];
   var starterPic = CustomData[5];
   var currentSlide = CustomData[6];
   var customChangeMethod = CustomData[7];
   var customEndMethod = CustomData[8];

   var numSlides = picArray.length;
   var completedSlideRotations = 0;
   
   self.getCurrentSlide = function ()
   {
      return currentSlide;
   }

   self.startSlideShow = function ()
   {
      var d = new Array(3);
     
      d[0] = picDir
      d[1] = picArray;
      d[2] = divName;

      if (showState == "Inactive")
      {
         if (currentSlide <= 0)
            currentSlide = 1;
         currentSlide--;
         
         timer = new IntervalTimer(d);               /* get a timer  */

         timer.IntervalMethod = changeSlideShow;     /* rotation routine  */ 
         timer.TimeSlice = changeFreq;               /* change picture every x seconds  */
         timer.Interval = changeFreq;                /* we have y pictures. Complete show in x*y seconds */
         timer.Rotations = -1;
         if (numSlideRotations <= 0)
            numSlideRotations = -1;
         
         if (starterPic != null)
           changeSlideShow(null, CustomData);

         completedSlideRotations = 0;
         showState = "Play";
         timer.StartTimer();                         /* Begin */
      }
   }   
   
   function changeSlideShow(timer, d)
   {
      directory = d[0];
      picArray = d[1];
      IdName = d[2];
      StartPic = d[5];
      
      HandleID = document.getElementById(IdName);

      if (timer == null)
      {
         picPath = directory + "/" + StartPic;
      }
      else
      {
         previousSlide = currentSlide;
         currentSlide++;
         if (currentSlide > numSlides)
         {
            currentSlide = 1;
            completedSlideRotations++;
            if ((numSlideRotations != -1) && (completedSlideRotations >= numSlideRotations))
            {
                 self.stopSlideShow();
                 if (customEndMethod != null)
                    customEndMethod();
                 return;
            }
         }
            
         picPath = directory + "/" + picArray[currentSlide - 1];
      }

      if ((customChangeMethod != null) && (timer != null))
         customChangeMethod(HandleID, picPath, previousSlide, currentSlide);
      else
      {
         HandleID.src = picPath;
         if (customChangeMethod != null)
            customChangeMethod(null, picPath, previousSlide, currentSlide); 
      }
   }  
   
   self.pauseSlideShow = function ()
   {
      if (showState == "Play")
      {
         timer.PauseTimer();
         showState = "Stop";
      }
   }

   self.restartSlideShow = function ()
   {
      if (showState == "Inactive")
         self.startSlideShow();
         
      if (showState == "Stop")
      {
         timer.RestartTimer();
         showState = "Play";
      }
   }
   
   self.stopSlideShow = function ()
   {
      if (showState != "Inactive")
      {
         timer.StopTimer();
         showState = "Inactive";
      }
   }
   
   self.moveToSlide = function (num)
   {
      if (num <= 0)
         num = 1;
         
      if (num > numSlides)
         num = numSlides;
         
      previousSlide = currentSlide;
      
      if (showState == "Play")
      {
         self.pauseSlideShow;
         currentSlide = num;
         CustomData[5] = picArray[currentSlide - 1];
         changeSlideShow(null, CustomData);
         CustomData[5] = starterPic;
         self.restartSlideShow();   
      }
      else
      {
         currentSlide = num;
         CustomData[5] = picArray[currentSlide - 1];
         changeSlideShow(null, CustomData);
         CustomData[5] = starterPic;
      }
   }
   
   self.firstSlide = function ()
   {
      self.moveToSlide(1);
   }
   
   self.nextSlide = function ()
   {  
      if (currentSlide >= numSlides)
         self.firstSlide();
      else
         self.moveToSlide(currentSlide + 1);
   }
   
   self.previousSlide = function ()
   {
      if (currentSlide <= 1)
         self.lastSlide();
      else
         self.moveToSlide(currentSlide - 1);
   }
   
   self.lastSlide = function ()
   {
      self.moveToSlide(numSlides);
   }
}

// -->
