/* ***************************************************************************************
 * File:             global.js
 * Description:      Global JavaScript utilities
 * Revision History: 2006-01-12 [am] File created
 * **************************************************************************************** */

/* *************************************************************************
 * *************************************************************************
 * Global Constants & Variables 
 * *************************************************************************
 * ************************************************************************* */

/* *************************************************************************
 * *************************************************************************
 * Global Functions
 * *************************************************************************
 * ************************************************************************* */
 
/* *****************************************
 * Function:    Init
 * Description: Initialization when page loads
 * Arguments:   None
 * Return:      None
 * ***************************************** */
function Init() {
   InitRollover();
   if(window.InitCustom) {
      InitCustom();
   }
   return true;
}

/* *****************************************
 * Function:    InitRollover
 * Description: Init rollover images
 * Arguments:   None
 * Return:      None
 * ***************************************** */
function InitRollover() {
   /* Verify browser supports images */
   if(!document.getElementById) return;
   
	var imgOriginSrc;
	var imgTemp       = new Array();
	var imgArray      = document.getElementsByTagName('img');
	
	/* For each image in document, if hsrc element exists, it will be the rollover image */
   for(var i = 0; i < imgArray.length; i++) {
      /* src is normal image */
      imgTemp[i] = new Image();
      imgTemp[i].src = imgArray[i].getAttribute('src');
      
      /* hsrc attribute is rollover image */
      if(imgArray[i].getAttribute('hsrc') && !imgArray[i].getAttribute('csrc')) {
         imgTemp[i] = new Image();
         imgTemp[i].src = imgArray[i].getAttribute('hsrc');
         
         /* rollover function */
         imgArray[i].onmouseover = function() {
            imgOriginSrc = this.getAttribute('src');
            this.setAttribute('src',this.getAttribute('hsrc'));
         }
         
         /* rollout function */
         imgArray[i].onmouseout = function() {
            this.setAttribute('src',imgOriginSrc);
         }
      }
   }
}

/* *****************************************************************************
 * Object:      ImageRotatorObj
 * Description: Object to rotate image
 * ***************************************************************************** */
function ImageRotatorObj(imgName, imgPath, rotateSpeed) {
   this.index = 0;
   this.timer = 0;
   this.speed = rotateSpeed;
   this.path = imgPath;
   this.imgObj = document.images[imgName]; // Get reference to image object
} 

ImageRotatorObj.prototype = {
   addImages: function() {
      this.imgObj.imageArray = [];
      for(var i = 0; arguments[i]; i++) {
         this.imgObj.imageArray[i] = new Image();
         this.imgObj.imageArray[i].src = this.path + arguments[i];
      }
   },
   
   rotate: function() {
      this.index = (this.index < this.imgObj.imageArray.length - 1) ? this.index + 1 : 0;
      this.imgObj.src = this.imgObj.imageArray[this.index].src;
   },
   
   start: function(objectName) {
      this.index = this.imgObj.imageArray.length;
      this.rotate();
      this.timer = setInterval(objectName + ".rotate()", this.speed);
   }
}

/* *************************************************************************
 * *************************************************************************
 * Main
 * *************************************************************************
 * ************************************************************************* */
onload=Init; 
