function resolveMenu(url) {
  // MSIE uses \ when everyone else uses /
  url = url.replace(/\\/g, '\/');

  var selectedMenu;
  var anchors = document.getElementsByTagName('A');
  var obj;
  findObj:
    for (var z=0;z<anchors.length;z++) {
      //alert(url+"\n"+anchors[z].href);
      if (anchors[z].href && url == anchors[z].href.replace(/\\/g, '\/')) {
        // Got matching link, but is it part of the menu?
        obj = anchors[z];
        while (obj) {
          if (obj.className == 'menu') {
            selectedMenu = obj;
            break findObj;
          }
          obj = obj.parentNode;
        }
      }
    }
  if (!selectedMenu) return false;

  // Create an array of divs to be hidden.
  var hideDivs = new Array();

  // Find all menu elements
  var divs = document.getElementsByTagName('DIV');
  var div;
  for (var z=0;z<divs.length;z++) {
    div = divs[z];
    if (div.className == "menu")
      hideDivs.push(div);
  }

  // Reveal relevant elements
  var walkNode = selectedMenu;
  while (walkNode) {
    for (var x=0; x<walkNode.childNodes.length; x++)
      if (walkNode.childNodes[x].className == "menu")
        for (var z=0;z<hideDivs.length;z++)
          if (hideDivs[z] == walkNode.childNodes[x])
            hideDivs.splice(z, 1);
    walkNode = walkNode.parentNode;
  }

  // Hide unwanted divs
  for (var z=0;z<hideDivs.length;z++)
    hideDivs[z].style.display = 'none';
  hideDivs = 0;

  rec_highlightlinks(selectedMenu);
  return true;
}

// Walk the DOM looking for links and change their colour.
function rec_highlightlinks(obj) {
  if (obj.href)
    obj.style.color = "#c7616b";
  else
    for (var x=0; x<obj.childNodes.length; x++)
      if (obj.childNodes[x].className != "menu")
        rec_highlightlinks(obj.childNodes[x]);
}

// If the menuURL hasn't already been defined, use the page's location.
if (!window.menuURL)
  window.menuURL = document.location.protocol+'//'+document.location.host+document.location.pathname;
resolveMenu(window.menuURL);

