//copyright © 2005 Dave Carnaghan
//Navigation Bar Builder
//for www.realtimethrill.com

//Uses colourRun.js
//There is one instance of the ColourRun
//"class" per nav element.

//Unlike 23Frames version, the nav bar is 
//reloaded along with the pages it points to.
//buildMenu() must be called within the <body>
//of each page. A nav[] relates to each of 
//the site's pages.

//TO DO: re-code buildMenu() without a table!
//TO DO: re-code buildMenu() using DOM, 
//instead of document.write() 

nav = new Array();
/*---EDIT BELOW TO CUSTOMISE THE MENU---*/
nav[0]={label:"news", rsrc:"news.html"};
nav[1]={label:"about", rsrc:"about.html"};
nav[2]={label:"lyrics", rsrc:"lyrics.html"};
nav[3]={label:"music", rsrc:"music.html"};
nav[4]={label:"links", rsrc:"links.html"};
nav[5]={label:"photos", rsrc:"photos.html"};
nav[6]={label:"creds", rsrc:"credits.html"};

//nav colours
var active='#5A5A29'; //#525221
var inActive='#81814E'; //must match up with .navMenu

/*---DO NOT EDIT BEYOND THIS POINT---*/

//a nav (table cell) object reference
var currentNav;

function setCurrentNav()
{
  //(IDs needed at all only to give currentNav its value)
  var theId;

  //page variable is on each HTML page
  var found=false;
  var index=0; 
  while (index < nav.length && !found)
  {
    if (nav[index].label != page) index++;
    else found=true;
  }

  if (index == nav.length) 
  {
    document.write("admin error: this page is not correctly");
    document.write(" registered with the navigation bar.");
    return;
  }

  theId="navMenu"+nav[index].label;

  currentNav=document.getElementById(theId);

  currentNav.style.cursor = "default";
  currentNav.style.backgroundColor=active;
}

function hoverOver(cell, onMousOvr)
{
  if (cell == currentNav) return;

  if (onMousOvr){
    //for the non-colourRun version
    //cell.style.backgroundColor=active;

    if (!cell.loading)
      cell.colourRunObj.startColourRun();
  }else{ 
    //for the non-colourRun version
    //cell.style.backgroundColor=inActive;

    if (!cell.loading)
      cell.colourRunObj.stopColourRun();
  }
}

function navgte(rsrce, cell)
{
  if (cell == currentNav) return;

  //cell.style.cursor = "default";
  cell.colourRunObj.stopColourRun();
  cell.loading = true;

  window.location=rsrce;
}

function buildMenu()
{
  document.write('<table style="margin-top:1px; margin-left:auto; margin-right:auto;" cellspacing="2" width="442px"> <tr>'); 

  for (var point=0; point<nav.length; point++) {
    document.write('<td id=' +"navMenu"+nav[point].label+ ' class="navMenu" onMouseOver="hoverOver(this,true);" onmouseout="hoverOver(this,false);" onmouseup="navgte(\u0027' +nav[point].rsrc+ '\u0027,this)">' +nav[point].label+ '</td>');
  }

  document.write('</tr></table>');

  setCurrentNav();

  //For use of colourRun.js
  //Add a property to each nav element referencing  
  //its own ColourRun instance.
  var element = null;
  var delay = -2;
  for (var i=0; i<nav.length; i++) {
    element = document.getElementById("navMenu"+nav[i].label);
    element.colourRunObj = new ColourRun(element, delay+=10);
    //alert(delay);

    element.loading = false;
  }
}
