// general_fader.js - handles billboards, banners, etc.

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

// Start of Global variables setup

// Billboards
  var billboard_index = 0;	// Initial index to fader list
  var billboard_count = 0;	// Initialize count
  var billboard_list;
  var billboard_time = 7000;	// 7 seconds between billboard fades

// Banners
  var banner_index = 0;
  var banner_count = 7;
  var banner_list;
  var banner_time = 28000;	// 28 seconds between banner fades

  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, out/in) - this function resets (fades out initially) by setting zIndex to 0
    
  function fadeInit(id, inval)	// in=1 => bring to front
    {
    var objectStyle;
    
    objectStyle = document.getElementById(id).style;
    if (! inval)
      {
      objectStyle.zIndex=0;		// FALSE, Push to back
      changeOpac(0, id);		// Reset opacity to 0
      }
    else				// TRUE
      {
      objectStyle.zIndex=4;
      changeOpac(100, id);
      };
    }


// *----------------------------------------------------------------------------*
// *	billboard recycle_event - processes timer interval and fades windows	*
// *----------------------------------------------------------------------------*
    
  function billboard_recycle_event()
    {
    if (billboard_count < 2) return;			// Only do this if multiple faders
    old_div = billboard_list[billboard_index++];		// Get current fader div id, bump index
    if (billboard_index >= billboard_count) billboard_index=0;	// Reset/wrap index if at limit
    new_div = billboard_list[billboard_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("billboard recycle event happened<br><br>Old div: " + old_div + ";  New div: " + new_div  ); */	// temporary debug
    setTimeout("billboard_recycle_event()", billboard_time);	 // re-start recycle timer
    }


// *----------------------------------------------------------------------------*
// *	banner recycle_event - processes timer interval and fades windows	*
// *----------------------------------------------------------------------------*
    
  function banner_recycle_event()
    {
    if (banner_count < 2) return;			// Only do this if multiple faders
    old_div = banner_list[banner_index++];		// Get current fader div id, bump index
    if (banner_index >= banner_count) banner_index=0;	// Reset/wrap index if at limit
    new_div = banner_list[banner_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("banner recycle event happened<br><br>Old div: " + old_div + ";  New div: " + new_div  ); */	// temporary debug
    setTimeout("banner_recycle_event()", banner_time);	 // re-start recycle timer
    }






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

  function onload_kickoff()
    {

// First, initialize billboards

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

// Define up to N billboards ...

    billboard_list[k++] = "div_billboard1";
    billboard_list[k++] = "div_billboard2";
    billboard_list[k++] = "div_billboard3";
    billboard_list[k++] = "div_billboard4";
    billboard_list[k++] = "div_billboard5";
    billboard_list[k++] = "div_billboard6";
    billboard_list[k++] = "div_billboard7";
  
    for (k=0; k<billboard_count; k++)
      fadeInit(billboard_list[k], 0);		// Initialize each div

    billboard_index=0;
    fadeIn(billboard_list[0]);		// fade in first billboard
    setTimeout("billboard_recycle_event()", billboard_time); // kickoff the first recycle event

// Now do banners

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

// Define up to N banners ...

    banner_list[k++] = "div_banner1";
    banner_list[k++] = "div_banner2";
    banner_list[k++] = "div_banner3";
    banner_list[k++] = "div_banner4";
    banner_list[k++] = "div_banner5";
    banner_list[k++] = "div_banner6";
    banner_list[k++] = "div_banner7";
//    banner_list[k++] = "div_banner8";
  
//    banner_count = k;				// Total banner faders

    for (k=1; k<banner_count; k++)
      fadeInit(banner_list[k], 0);		// Initialize each div

    banner_index=0;
    fadeInit(banner_list[0], 1 );		// fade in first banner

    setTimeout("banner_recycle_event()", banner_time); // kickoff the first recycle event

    }
