// index.jsp.js

/* Constants */
var Browser = new BrowserInfo();

var HOME_MENULIST = new Array("PromoContent");

var PromoContent = new Object();

PromoContent.promoElement;
PromoContent.element;
PromoContent.url;
PromoContent.click = function(e)
{
    window.location.href = PromoContent.url;
}
PromoContent.init = function(e)
{
    PromoContent.promoElement = document.getElementById("Promo");
    PromoContent.element = document.getElementById("PromoContent");
    
    if(PromoContent.promoElement != null)
    {
        PromoContent.url = PromoContent.promoElement.getElementsByTagName("a")[0].href;
    }        
    
    if(PromoContent.element != null)
    {
        addEventHandler(PromoContent.element, "click", PromoContent.click, false, false);
    }
}

var ContentOverlay = new Object();
ContentOverlay.element;
ContentOverlay.click = function(e)
{
    stopEventBubble(e);
}

ContentOverlay.init = function(e)
{
    ContentOverlay.element = document.getElementById("ContentOverlay");
    if(ContentOverlay.element != null)
    {
        addEventHandler(ContentOverlay.element, "click", ContentOverlay.click, false, false);
    }
}


var BigImage = new Object();
BigImage.element;
BigImage.click = function(e)
{
	if (BigImage$sURL != "")
	{
	    if(BigImage$bOpenInNewWindow)
	    {
	        window.open(BigImage$sURL);
	    }
	    else
	    {
	        window.location.href = BigImage$sURL;
	    }
	}
}

BigImage.init = function(e)
{
    BigImage.element = document.getElementById("BigImage");
    if(BigImage.element != null)
    {
        addEventHandler(BigImage.element, "click", BigImage.click, false, false);
    }
}

//function homepage_load(e)
//{
//    Flash_HomePageFeatures();
//}

// Page Event Handlers
//addEventHandler(window, "load", homepage_load, false, true);

// Hacks
function hack_ContentOverlayOpacity()
{
    var ContentOverlay = document.getElementById("ContentOverlay");
    
    // IE 4 - 7
    if(Browser.name == "WinIE" && Browser.browserVersion >= 4)
    {
        ContentOverlay.style.filter = "alpha(opacity=100)";
    }
    
    // Mozilla-based Browsers through Firefox 1.5
    // Firefox 2 supports the CSS 3 property "opacity."
    if(ContentOverlay.style.MozOpacity)
    {
        ContentOverlay.style.MozOpacity = "1";
    }
}

/* HomePage Feature Rotation witn Image transition related code */
 
/***** Global variable declarations ***/
var elementTag=document.getElementsByName("photo");
var currentPhoto = 0;
var secondPhoto = 1;
var pause = false;
var currentOpacity = new Array();
var FADE_STEP = 2;
var FADE_INTERVAL = 65;
// variable for play/pause toggle
var play;
//variable that will increment through the images
var num=0
// set the delay between images
var timeDelay
var mInterval=0;
var mInterval2=0;
//preload the images in the cache so that the images load faster
var imagePreload=new Array()
var imagePreloadurls = new Array()
for (i=0;i<image.length;i++)
{
  imagePreload[i]=new Image()
  //set the src attribute
  imagePreload[i]=image[i].url;
  imagePreloadurls[i]=image[i].imageLink;
}
/***** End Global variable declarations ***/

// Image transition related code
 function init() 
 {
 	setOpacity(0);  //to set opacity value 
 	DisplayImage(); //to display images 
 	if(document.all) 
 	{
 		document.getElementsByName("photo")[currentPhoto].style.filter="alpha(opacity=100)";
 	} 
 	else 
 	{
 		document.getElementsByName("photo")[currentPhoto].style.MozOpacity  = .99;
 		document.getElementsByName("photo")[currentPhoto].style.Opacity  = .99;
 		document.getElementsByName("photo")[currentPhoto].style.KhtmlOpacity  = .99;
 	}
 	mInterval = setTimeout("startSlideShow()",5000);
}

hex_description=255;
hex_title=0;// Initial color value.

var t1;
function fadetext()
{ 
    if(hex_title<102) { //If color is not black yet
    hex_title+=2; // increase color darkness
    document.getElementById("ImageTitle").style.color="rgb("+0+","+0+","+hex_title+")";
    document.getElementById("ClickDisplayUrl").style.color="rgb("+0+","+0+","+hex_title+")";
    t1=setTimeout("fadetext()",25); 
    }
    else
    hex_title=0; //reset hex value
   
}
clearInterval(t1);

//fade description
function fadetext_description()
{ 
    if(hex_description>139) { //If color is not black yet
    hex_description-=5; // increase color darkness
    links=document.getElementsByTagName("a"); 
    document.getElementById("ImageDescription").style.color="rgb("+hex_description+","+hex_description+","+hex_description+")";
    if( document.getElementById('BlurbId'))  
    {
        document.getElementById('BlurbId').style.color="rgb("+hex_description+","+hex_description+","+hex_description+")";
        document.getElementById('BlurbId').onmouseover=function() //onmouse over the link color is set to blue shade
        {
               document.getElementById('BlurbId').style.color="#003366";
        }
            document.getElementById('BlurbId').onmouseout=function() //mouseout the link color is set to gray shade
        {
              document.getElementById('BlurbId').style.color="#878787";
        }
       
    }
    
    //document.getElementById("BlurbId").style.color="rgb("+hex_description+","+hex_description+","+hex_description+")";
    setTimeout("fadetext_description()",25); 
    }
    else
    hex_description=255 //reset hex value
}

 function startSlideShow()
 {
 	mInterval = setInterval("crossFade()",FADE_INTERVAL);
 	
 }
 var doneTitle;
 doneTitle = false;
 
// function to display the Images
function DisplayImage()
{
    mHTML="";
    for(i=0;i<imagePreload.length;i++)
 	{ 	   
 	   mHTML+="<div id=\"photo\" name=\"photo\" class=\"mPhoto\"><img src= \""+imagePreload[i] +"\"  width=\""+imgWidth +"\" height=\""+imgHeight+"\"></div>";
 	   
   	}
	document.getElementById("ImageLoader").innerHTML = mHTML;
}
 
 // function to set the opacity value
 function setOpacity(imgIndex)
 {
	for(i=0;i<imagePreload.length;i++)
	{
	    currentOpacity[i]=0;
	}   
	currentOpacity[imgIndex]=99;
 } 
   
 // Function to set the opacity property for different browser.
 function Browser_Opacity(currentPhoto,secondPhoto)
 {
       if(document.all) 
       {
           elementTag[currentPhoto].style.filter = "alpha(opacity=" + currentOpacity[currentPhoto] + ")";
           elementTag[secondPhoto].style.filter = "alpha(opacity=" + currentOpacity[secondPhoto] + ")";
       } 
       else 
       {
          document.getElementsByName("photo")[currentPhoto].style.MozOpacity  = currentOpacity[currentPhoto]/100;
 		  document.getElementsByName("photo")[secondPhoto].style.MozOpacity  =currentOpacity[secondPhoto]/100;
 		  document.getElementsByName("photo")[currentPhoto].style.Opacity  = currentOpacity[currentPhoto]/100;
 		  document.getElementsByName("photo")[secondPhoto].style.Opacity  =currentOpacity[secondPhoto]/100;
 		  document.getElementsByName("photo")[currentPhoto].style.KhtmlOpacity  = currentOpacity[currentPhoto]/100;
 		  document.getElementsByName("photo")[secondPhoto].style.KhtmlOpacity  = currentOpacity[secondPhoto]/100;
       } 
 }
         
// function to display the Image title,description and the page Identity
function ImageDescription(num,imagevalue,imageLink,imageOnClick)
{
		var imageFullLink = "";
		if(imageLink.indexOf("javascript:open_window") >= 0)
        {
			imageLink = imageLink.substring(0, imageLink.length - 2) + "?cm_sp="+trackInfo+"-_-SlideShow-_-Slide" +imagevalue+"')";
			imageFullLink = imageLink.substring(imageLink.indexOf("'") + 1, imageLink.length - 2);
			imageOnClick = "cmCreateManualLinkClickTag('" +  imageFullLink  + "','Slide"+imagevalue+"','"+ imageFullLink +"')";
		}
		else
		{
			imageLink = imageLink + "?cm_sp="+trackInfo+"-_-SlideShow-_-Slide"+imagevalue;
			imageOnClick = "cmCreateManualLinkClickTag('"+ imageLink +"','Slide"+imagevalue+"','" + imageLink + "')";
		}
		document.getElementById("ImageLoader").onclick = function() //calling a function to make the images clickable
		{
		     if(imageLink.indexOf("javascript:open_window") >= 0)
		     {
		     	imageFullLink = imageLink.substring(imageLink.indexOf("'") + 1, imageLink.length - 2);
		        cmCreateManualLinkClickTag(imageFullLink ,"Slide"+imagevalue, imageFullLink);
		        window.open(imageFullLink);
		     }
		     else
		     { 
		        window.location=imageLink;
		        cmCreateManualLinkClickTag(imageLink ,"Slide"+imagevalue , imageLink);
		     }
        }
          
          //fadetext();
       	  document.getElementById("ImageTitle").innerHTML="<a id=ClickDisplayUrl href="+imageLink +"\n"+"onClick="+imageOnClick+">"+image[num].title+"</a>";
       	  //fadetext_description();
		  document.getElementById("ImageDescription").innerHTML=image[num].desc;
		  document.getElementById("PageIdentity").innerHTML="<font color=#00417b><b>"+imagevalue+"</b></font>" +"\n"+"of"+ "\n"+image.length;
	
}
function fadeContents()
{ 
    fadetext();
    fadetext_description();
}
  
 function crossFade() 
 {
     if(pause)return;   
  
 	currentOpacity[currentPhoto]-=FADE_STEP;
 	currentOpacity[secondPhoto] += FADE_STEP;
 	Browser_Opacity(currentPhoto,secondPhoto); //calling the function to set the opacity property depending on the browser.
    if(currentOpacity[secondPhoto]/100 >=.1) 
 	{   
 	    if (!doneTitle)
 	    {
 	        if (num<image.length)
	        {
		        num++
		        //if last image is reached,display the first image
		        if (num==image.length) 
		        num=0
		        //pagination 
		        var imagevalue=num+1;
		        var imageLink = image[num].imageLink;
		        var imageOnClick = "";
		        fadeContents();
		       ImageDescription(num,imagevalue,imageLink,imageOnClick); // function to display the Image related Contents
		       
	        }
	        doneTitle = true;
 	    }
    }
  	if(currentOpacity[secondPhoto]/100>=.98) 
 	{   
 	    doneTitle = false;
 		currentPhoto = secondPhoto;
 		secondPhoto++;
 		if(secondPhoto == imagePreload.length)
 		{
 		    secondPhoto=0;
	    }
 		pause = true;
 		xInterval = setTimeout("pause=false",5000);
 	}
 	
 }
 
//function to get the previous image in the array
function previous_image()
{  
    pause=true;
    pause_image();
    if (num>=0)
    {
       if (num==0) 
       {
            num=imagePreload.length-1;
            currentPhoto=num;
            secondPhoto=1; 
       }
       else
       {
            currentPhoto=num-1;
            secondPhoto=num; 
            num--;  
       }
       //DisplayImage(); //to display images
       //note: we don't need to call this everytime we click prev or next since we have already drawn the images in the init.
       //redrawing the images everytime causes a flicker issue in IE - Craig
       setOpacity(num); //to set opacity value 
       Browser_Opacity(currentPhoto,secondPhoto); //calling the function to set the opacity property depending on the browser.
       var imagevalue=num+1;
 	   var imageLink = image[num].imageLink;
	   var imageOnClick = "";
       ImageDescription(num,imagevalue,imageLink,imageOnClick); // function to display the Image related Contents
      }
}
 	
//function to get the next image in the array
function next_image()
{   
    pause=true;
    pause_image();
    if (num< imagePreload.length)
    { 	
    	if(num == imagePreload.length -1) 
	    {
	    	currentPhoto=num;
	        secondPhoto=0; 
	        num=0;
	    }
	    else
	    {
            currentPhoto=num;
            secondPhoto=num+1; 
            num++;  
        }
        //DisplayImage(); //to display images
        //note: we don't need to call this everytime we click prev or next since we have already drawn the images in the init.
        //redrawing the images everytime causes a flicker issue in IE - Craig
 	    setOpacity(num); //to set opacity value 
        Browser_Opacity(currentPhoto,secondPhoto); //calling the function to set the opacity property depending on the browser.
        var imagevalue=num+1;
		var imageLink = image[num].imageLink;
		var imageOnClick = "";
        ImageDescription(num,imagevalue,imageLink,imageOnClick); // function to display the Image related Contents
	    } 
	    doneTitle = true;
}

//for pausing Slideshow of the Images
function pause_image()
{ 
    clearInterval(mInterval);
    pause=true;
    if(pause) 
    {
     document.getElementById("PlayToggle").style.display="block";
     document.getElementById("PauseToggle").style.display="none";
     document.getElementById("PlayToggle").style.marginLeft="27px";
     document.getElementById("PlayToggle").style.marginTop="-3px"
    }
}

//  for playing Slideshow of images 
function play_image()
{    
    pause=false;
    document.getElementById("PlayToggle").style.display="none";
    document.getElementById("PauseToggle").style.display="block";
    mInterval = setInterval("crossFade()",FADE_INTERVAL);
}

