/*----------------------------------------------------------------------+
|********************  Copyright 2002, Kyle McKenzie  *******************
|------------------------------------------------------------------------
|  Title:     Easy Ad Rotator
|  Filename:  ad_rotator.js
|  Author:    Kyle McKenzie
|
|  Date       Description
|  ---------- ----------------------------------------
|  02/15/2002 Initial version
|  02/15/2002 Added resize fix for Netscape 4.x browsers
|
+----------------------------------------------------------------------*/


//***********************************************
// First set some global variables
//***********************************************
RT_INTERVAL = 23;     //Number of seconds to show each banner
RT_WIDTH = 468;       //Width of banner ad. For NS LAYER only
RT_HEIGHT = 60;       //Height of banner ad. For NS LAYER only
RT_OFFSET_X = 6;      //Layer offset from top of page. For NS LAYER only
RT_OFFSET_Y = 8;      //Layer offset from right of page. For NS LAYER only       

//***********************************************
//Next define the ads array
//***********************************************
RT_ARRAY = [
  ["021298-3.gif","http://host41.hrwebservices.net/~wacostr/forums/sponsors.html","click here for more information"],
  ["021298-3.gif","http://host41.hrwebservices.net/~wacostr/forums/sponsors.html","click here for more information"],
  ["021298-3.gif","http://host41.hrwebservices.net/~wacostr/forums/sponsors.html","click here for more information"],  
  ["021298-3.gif","http://host41.hrwebservices.net/~wacostr/forums/sponsors.html","click here for more information"]];
  
//***********************************************
//Proload the images so the banner snaps
//***********************************************
function loadImages(){
  var d = document; 
  if(d.images){
    if(!d.imgArr) d.imgArr = new Array();   
    for(i=0; i<RT_ARRAY.length; i++){
      var x=d.imgArr.length;
      if(RT_ARRAY[i][0].indexOf("#")!=0){
        d.imgArr[x]=new Image; 
        d.imgArr[x++].src=RT_ARRAY[i][0];
      }
    }
  }
}

//***********************************************
//Resets the rotation if the browser was resized
//***********************************************
function resetBanner(e){
  clearTimeout(document.timer)
  if(e) routeEvent(e);
  document.banIdx = 0;   
  rotate();
}

//***********************************************
//Rotate the banners delayed by specified number
//of seconds
//***********************************************
function rotate(){
  var d=document;
  var w=window;
  if(d.banIdx >= RT_ARRAY.length) d.banIdx=0;
  var bImg = RT_ARRAY[d.banIdx][0];
  var bUrl = RT_ARRAY[d.banIdx][1];
  var bAlt = RT_ARRAY[d.banIdx][2];  
  
  if(is_ie4up || is_nav6up){
    banner.innerHTML = '<a target="_blank" href="'+ bUrl +'"><img src="'+ bImg +'" border="0" alt="'+ bAlt +'"></a>';
  } 
  else{
    w.captureEvents(Event.RESIZE);
    w.onResize = resetBanner;   
    d.banner.top = RT_OFFSET_Y;
    d.banner.left = ((w.innerWidth-RT_OFFSET_X)-RT_WIDTH);
    d.banner.document.write('<a target="_blank" href="'+ bUrl +'"><img src="'+ bImg +'" border="0" alt="'+ bAlt +'"></a>');
    d.banner.document.close();      
  } 
  d.banIdx++;
  d.timer = setTimeout("rotate()",(RT_INTERVAL*1000));  
  
}

//***********************************************
//Initialize the ad_rotator when the page loads
//***********************************************
function loadBanner(){
  document.banIdx = 0; 
  loadImages();
  rotate();
  }

//***********************************************
//Display the appropriate tag for the banner
//***********************************************
function showBanner(){
  if(is_ie4up || is_nav6up){
    styleString = (is_ie4up) ? "visible;" : "show;";
    document.write('<DIV ID="banner" STYLE="position:relative;visibility:'+ styleString +'"></DIV>');
    }
  else{
    document.write('<LAYER ID="banner" HEIGHT="'+ RT_HEIGHT +'" WIDTH="'+ RT_WIDTH +'" VISIBILITY="show" ></LAYER>');
    }  
  } 