﻿/***********************************************************
******************** IMAGE CLASS ***************************
************************************************************/

function image(pContainerID, pNavBarItemID, pValue, pImageName)
{
    this.value = pValue;
    this.imageName = pImageName;
    this.containerID = pContainerID;
    this.navBarItemID = pNavBarItemID;
}

/***********************************************************
**************** IMAGE ROTATOR CLASS ***********************
************************************************************/

function imageRotator(pControlID, pWidth, pHeight)
{
    this.totalImages=0;
    this.selectedIndex=-1;
    this.selectedImage=null;
    
    this.controlID = pControlID;                
    this.width = pWidth;
    this.height = pHeight;    
    this.images = new Array();
    this.timeoutIDs = new Array();
    
    
}

// FUNCTION TO ADD NEW IMAGE OBJECT IN LIST
imageRotator.prototype.addImage = function(pImage)
                                  {
                                    this.images[this.totalImages] = pImage;
                                    this.totalImages++;
                                  } 

// FUNCTION TO SET IMAGE IN THE IMAGE BOX
imageRotator.prototype.displayImage = function(pIndex)
                                  {
                                  
                                      if(this.selectedImage)
                                      {
                                        this.selectedImage.style.display = "none";
                                      }
                                  
                                      this.selectedIndex = pIndex;                                    
                                      var img = this.images[pIndex];
                                      this.selectedImage = document.getElementById(img.containerID);
                                      this.selectedImage.style.display = "block";
                                      
                                  }
                                  
 imageRotator.prototype.displayImageByOpacity = function(pIndex)
                                  {
                                        // REMOVE PREVIOUS TIME OUT
                                        var len = this.timeoutIDs.length;
                                        for(var i=len;i>0 ;i-=1)
                                        {
                                            clearTimeout(this.timeoutIDs[i]);
                                           // delete this.timeoutIDs[i];
                                        }
                                    
                                        var speed = 20;                                       
                                        var opacity=100;
                                        var containerID = this.images[pIndex].containerID;
                                          
                                        // HIDE DIV
                                       // for(var i=1;i<=100;i+=1)
                                       // {   
                                        //    opacity-=1;          
                                        //    setTimeout("changeOpacity('"+this.imageContainerID+"', "+opacity+")", i * speed);
                                        //}
                                        changeOpacity(containerID,0) ;
                                        
                                        // CHANGE IMAGE
                                       //setTimeout("displayImage("+pIndex+")", 101 * speed, this);
                                       this.displayImage(pIndex);
                                       
                                       // Show DIV                                       
                                        for(var i=0;i<=100;i+=1)
                                        {
                                           this.timeoutIDs[i] = setTimeout("changeOpacity('"+ containerID +"',"+i+")", i * speed);
                                        }
                                       
                              }
                                  
                                  
        function changeOpacity(id,opacity) 
        {       
           // alert(opacity);
            var obj = document.getElementById(id).style;
            obj.opacity = (opacity / 100);
            obj.MozOpacity = (opacity / 100);
            obj.KhtmlOpacity = (opacity / 100);
            obj.filter = "alpha(opacity=" + opacity + ")";
        }