function startup()
{
/* 

function: to highlight the menu item, this is done by retieving the 
page currently in the browser, and which link in the navigation matches
the page.

This script requires a class to be added to the css:

selected, as in a.selected:link, a.selected:visted { color: #fff;} - which styles the link

*/

// Start by retrieving the name of the navigation element, in this case a 
// div with an id of 'menu', and if it doesn't exist skip the rest of the script...

var nav = window.document.getElementById('menu');
if(nav != null)
{
  var thispageurl = window.location.href.toLowerCase();

  // if homepage and no page then add index.html
  if (thispageurl.substring (thispageurl.length-5, thispageurl.length) != '.html') {
	thispageurl=thispageurl+'index.html'
	}

  // retrieve the url of the page and clean it up...
  var sloc = thispageurl.replace('.html','/').replace('//','/');
		
  // retrieve all the links (a href) within the navigation...
  var as = nav.getElementsByTagName('a');

		
  //loop over all the a href links
  for(var i=0; i< as.length;i++) {
		
    // for each link in the loop, remove unwanted data...
    var sAloc = as[i].href.toLowerCase();
    sAloc = sAloc.replace('.html','/').replace('//','/').replace('//','/');

    // check if the current page is the same as this link...
    if(sAloc == sloc) {

      // then we have the current page
      // sn is a LI element that may contain a subnav

      var sn=as[i].parentNode;
      
      // show the child UL block 

      if (sn.childNodes.length > 0) {
        for (j=0; j<sn.childNodes.length; j++){
          var cn=sn.childNodes[j];
          if (cn.nodeName=="UL") {
            cn.style.display="block";
            }
          }  
        }

      // and if necessary, the parent UL block

      if (sn.parentNode.className == "subnav") {
        // set the parent
        sn.parentNode.style.display="block";
        }

      // and if necessary, the grandparent UL block

      if (sn.parentNode.parentNode.parentNode.className == "subnav") {
        // set the parent
        sn.parentNode.parentNode.parentNode.style.display="block";
        }

      // set current menu item class to selected
      
      as[i].className = 'selected';
      
      }
      else
      {
      
      var sn=as[i].parentNode;
      
      // show the child UL block 

      if (sn.childNodes.length > 0) {
        for (j=0; j<sn.childNodes.length; j++){
          var cn=sn.childNodes[j];
          if (cn.nodeName=="UL") {
            cn.style.display="none";
            }
          }  
        }      
      }
    }
  }
}

startup;


