// billboard_fader.js
// This handles fade in/out of specified entries in the fader list.

// Start of Global variables setup

  var fader_index = 0;	// Initial index to fader list
  var fader_count = 0;	// Initialize count
  var fader_list;

  ie4 = ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4 ))
  ns4 = ((navigator.appName == "Netscape") && (parseInt(navigator.appVersion) >= 4 ))

 if (ns4) {
  layerRef="document.layers";
  styleRef="";
}
          
 if (ie4) {
       layerRef="document.all";
       styleRef=".style";
}       

  

// End of Global variables setup


// function setdivxy
// sets the divid position to the specified x,y (left,top) position.  Browser-independent.

function setdivxy(divid, curx, cury)
  {
  if (ie4)
     {
     eval(layerRef + '["' + divid +'"]' + styleRef + '.top = cury');
     eval(layerRef + '["' + divid +'"]' + styleRef + '.left = curx');
     }
  else
     {
     document.getElementById(divid).style.left = curx + "px";
     document.getElementById(divid).style.top = cury + "px"; 
     };
  }


// function getXPos(id) - Gets the x (left) position of the division id

function getXPos(divid)
    {
    var retX;
    
//    retX =  document.getElementById(divid).style.left;
    retX = window.parent.pageXOffset;
    return(retX);
    }



// Function to display debug info in a new window, which can then be closed

  function showDebug(debuginfo)
    {
    newWin = window.open("","", "height=400,width=500"); // Creat a debug window
    newWin.document.write(debuginfo);
    newWin.document.close();
    }

// fadeIn(id) - this function fades IN the specified id in to primary image and sets the sIndex

  function fadeIn(id)
    {
    var objectStyle;
    
    objectStyle = document.getElementById(id).style;
    opacity(id, 0, 100, 1000);
    objectStyle.zIndex=4;    		// Pull to front
    }

// fadeOut(id) - this function fades OUT the specified id in to primary image and sets the sIndex
    
  function fadeOut(id)
    {
    var objectStyle;
    
    objectStyle = document.getElementById(id).style;
    opacity(id, 100, 0, 1000);
    objectStyle.zIndex=0;		// Push to back
    }

// fadeInit(id) - this function resets (fades out initially) by setting zIndex to 0
    
  function fadeInit(id)
    {
    var objectStyle;
    
    objectStyle = document.getElementById(id).style;
    objectStyle.zIndex=0;		// Push to back
    changeOpac(0, id);			// Reset opacity to 0
    }



// /*----------------------------------------------------------------------*
// *	recycle_event - processes timer interval and fades windows	*
// *----------------------------------------------------------------------*/
    
  function recycle_event()
    {
    if (fader_count < 2) return;			// Only do this if multiple faders
    old_div = fader_list[fader_index++];		// Get current fader div id, bump index
    if (fader_index >= fader_count) fader_index=0;	// Reset/wrap index if at limit
    new_div = fader_list[fader_index];			// Pointer to new fader

// Now swap the images ...

    fadeOut(old_div);					// Out with the old ...
    fadeIn(new_div);					// ... and in with the new !

// /*    showDebug("recycle event happened<br><br>Old div: " + old_div + ";  New div: " + new_div  ); */	// temporary debug
    setTimeout("recycle_event()", 7000);	 // re-start recycle timer
    }

// Set the following to be the startup function in your body statement

  function onload_kickoff()
    {
    var billboardx, billboardy;

//    billboardx = getXPos("div_billboard1");
//    showDebug("X = " + billboardx);

    fader_list = new Array();		// Array of faders
  
//  Define the faders for this page
  
    k=0;

// Define up to N billboards ...

//    fader_list[k++] = "div_billboard1";

    fader_list[k++] = "div_billboard1";
    fader_list[k++] = "div_billboard2";
    fader_list[k++] = "div_billboard3";
    fader_list[k++] = "div_billboard4";
    fader_list[k++] = "div_billboard6";

  
    fader_count = k;	// Total faders

    for (k=0; k<fader_count; k++)
      fadeInit(fader_list[k]);		// Initialize each div

    fader_index=0;
    fadeIn(fader_list[0]);		// fade in first billboard

    }

