/******************************************************************************
 *  FILENAME:     scripts.js                                                  *
 *  AUTHOR(S):    Greg Nenninger                                              *
 *  DATE CREATED: 10/15/2009                                                  *
 *  DESCRIPTION:  This file contains common reusable javascript code for      *
 *                LCHS website.                                               *
 *                                                                            *
 *  REVISION HISTORY:                                                         *
 *                                                                            *
 *  DATE        CHANGE BY     DESCRIPTION                                     *
 *  ========================================================================= *
 *  08/29/2009  G. Nenninger  File created.                                   *
 ******************************************************************************/

function Rotator () {
   this.array_index = 0;
   this.image_array = new Array ();
   this.image_delay = new Array ();
   this.item_array  = new Array ();
   this.t           = null;
   this.add_image   = add_image;
   this.add_item    = add_item;
   this.newpics     = newpics;
}

function add_image (image_name, delay)
{
   this.image_array[this.image_array.length] = new Image ();
   this.image_array[this.image_array.length - 1].src = image_name;
   this.image_delay[this.image_delay.length] = delay;
}

function add_item (item_name)
{
   this.item_array[this.item_array.length] = item_name;
}

function newpics ()
{
   max_delay = 0;
   for (i = 0; i < this.item_array.length; i++) {
      idx = (this.array_index + i) % this.image_array.length;
      this.item_array[i].src = this.image_array[idx].src;
      if (max_delay < this.image_delay[idx]) {
         max_delay = this.image_delay[idx];
      }
   }
   this.array_index = (this.array_index + 1) % this.image_array.length;

   thisObj = this;
   t = setTimeout (function() {thisObj.newpics ();}, max_delay, this);
}


