/* =====================================================================================
		SETTING UP THE SCRIPT'S VARIABLES
   ===================================================================================== */
var intLayerIn, intLayerOut, intOpacStart, intOpacEnd, blnCanFade, intTotalFrames, intcount, strBG_off, strBG_on;
intOpacStart = 0;
intOpacEnd = 100;
intLayerIn = 1;
blnCanFade = false;
intTotalFrames = intImageCount;
strBG_on = "#888888";
strBG_off = "#ffffff";

function homeDiv(strid,strElement)
{
 this.id = "Anim_" + strid;
 this.opacity = 0;
}

var arrHomeLayers = new Array();
for (intcount=1;intcount<=intTotalFrames;intcount++)
{
 arrHomeLayers[intcount] = new homeDiv(intcount);
}

/* =====================================================================================
		PRE-LOAD THE FOOTER NAV IMAGES & FUNCTION TO CHANGE
   ===================================================================================== */


function fn_ChangeFooterBGimage(intSectionID,state)
{
 var strState = ((state == 1) ? '_on' : '_off');
 eval(structure + "thumb_" + intSectionID + "').src = thumbImg_" + intSectionID + strState + ".src");
}

/* =====================================================================================
		FUNCTIONS TO OPERATE THE FADING ACTION
   ===================================================================================== */
//change the opacity for different browsers 
function changeOpac(opacity, intID)
{
 if(!blnCanFade){return;}
 if(!testElement(arrHomeLayers[intID].id)){return;}
 arrHomeLayers[intID].opacity = opacity;
 var object = document.getElementById(arrHomeLayers[intID].id).style; 
 object.opacity = (opacity / 100); 
 object.MozOpacity = (opacity / 100); 
 object.KhtmlOpacity = (opacity / 100); 
 object.filter = "alpha(opacity=" + opacity + ")";
// if(opacity==99){fn_elementDisplay(arrHomeLayers[intLayerOut].id,0);}
}

function fn_fadeLayers()
{
 var speed = Math.round(5); 
 var timer = 0; 
 var intFadeOut;
 fn_ChangeFooterBGimage(intLayerOut,0);
 fn_elementDisplay(arrHomeLayers[intLayerIn].id,1)
 for(intcount = 0; intcount <= 100; intcount++) 
 { 
  intFadeOut = intOpacEnd-intcount;
  setTimeout("changeOpac(" + intcount + ",'" + intLayerIn + "')",(timer * speed)); 
  setTimeout("changeOpac(" + intFadeOut + ",'" + intLayerOut + "')",(timer * speed)); 
  timer++;
  if(timer == 99)
  {
   fn_ChangeFooterBGimage(intLayerIn,1);
   setTimeout("fn_elementDisplay('" + arrHomeLayers[intLayerOut].id + "',0)",750);
  }
 } 
}

function fn_switchLayers()
{
 fn_ChangeFooterBGimage(intLayerOut,0);
 fn_elementDisplay(arrHomeLayers[intLayerOut].id,0);
 fn_elementDisplay(arrHomeLayers[intLayerIn].id,1);
 fn_ChangeFooterBGimage(intLayerIn,1)
}

/* =====================================================================================
		FUNCTIONS TO RUN THE DEFAULT LOOPING
   ===================================================================================== */
var blnContentBusy, cmd_doLoop;

blnContentBusy = false;
cmd_doLoop = setTimeout("",500);
var onContentTimeout = "doLoop()";

function doLoop()
{
 if(!blnContentBusy) 
 {
  intLayerOut = intLayerIn;
  intLayerIn = intLayerOut + 1;
  if(intLayerIn >= arrHomeLayers.length) {intLayerIn = 1;}
  if (blnCanFade) {fn_fadeLayers();}
  else {fn_switchLayers();}
  cmd_doLoop = setTimeout(onContentTimeout,3500);
 }
}

function contentBusy()
{
 blnContentBusy = true;
 clearTimeout(cmd_doLoop);
 cmd_doLoop = null;
}


/* =====================================================================================
		FUNCTIONS CALLED BY USER / BROWSER EVENTS
   ===================================================================================== */
function fn_homeRollover(intDiv)
{
 contentBusy();
 if(intDiv == intLayerIn){return;}
 intLayerOut = intLayerIn;
 intLayerIn = intDiv;
 if (blnCanFade) {fn_fadeLayers();}
 else {fn_switchLayers();}
}

function fn_RestartLoop()
{
 if(intImageCount == 1){return;}
 blnContentBusy = false;
 cmd_doLoop = setTimeout(onContentTimeout,2000);
}

function fn_setupHomeFades()
{
 if (intImageCount > 0)
 {
 var tmpStyleObject = document.getElementById(arrHomeLayers[1].id).style;
 if ((navigator.platform.indexOf('Win') > -1)) // if it's on anything other than Windows don't fade (because Mac's are tooooo sllooooowwwwwwwww ... 
 {
  if ((tmpStyleObject.opacity != "undefined") || (tmpStyleObject.MozOpacity != "undefined") || (tmpStyleObject.KhtmlOpacity != "undefined") || (tmpStyleObject.filter != "undefined"))
  {
   blnCanFade = true;
   for(intcount=1; intcount < arrHomeLayers.length; intcount++)
   {
    changeOpac(0, intcount);
   }
   changeOpac(100, 1);
  }
 }
 fn_elementDisplay(arrHomeLayers[1].id,1);
 fn_ChangeFooterBGimage(1,1)
 fn_RestartLoop();
}
}



