var aryLeftNav = null;
var strLeftNavID = "leftnavmain";
var strCrumbDivider = "";
var aryLinkChain = new Array();
var aryDefaultPage = new Array();
aryDefaultPage[aryDefaultPage.length] = "index.asp";
aryDefaultPage[aryDefaultPage.length] = "index.shtml";
aryDefaultPage[aryDefaultPage.length] = "index.html";
aryDefaultPage[aryDefaultPage.length] = "index.htm";

function buildCrumbs() {
  var myLink=null;
  var menu=null;
  var strCrumb="";

  // First we need to make sure the nav has been
  // "parsed" so we know the tree layout
  if(!aryLeftNav || !aryLeftNav.length)
    aryLeftNav = buildNavArray(document.getElementById(strLeftNavID));

  var pos = 0;
  var href = document.location.href;

  var myLink = aryLeftNav[href];

  // if the href cannot be found we first try
  // to truncate off any query parameters "?"
  // and check again.
  if(!myLink && (pos = href.indexOf("?")) > -1) {
    href = href.substring(0, pos);
    myLink = aryLeftNav[href];
  }

  // if we still don't have a link we check to see
  // if the page we are on is a "default" page if so
  // we truncate off the filename and check again
  if(!myLink) {
    pos = href.lastIndexOf("/");
    var file = href.substring(pos+1, href.length);
    if(file.length && aryDefaultPage.indexOf(file) > -1) {
      href = href.substring(0, pos+1);
      myLink = aryLeftNav[href];
    }
  }

  if(myLink) {
    dhtml.normalize(myLink);
	myLink.setClass("selected");
	if(myLink._overTarget && myLink._overTarget.length)
		myLink._overTarget[0].swap();
	myLink.lock();
	aryLinkChain[aryLinkChain.length] = myLink;
    strCrumb = '<a href="' + myLink.href + '">' + myLink.innerHTML + '</a>';
    menu = myLink.parentMenu;
  }

  while(menu && menu.parentLink) {
    aryLinkChain[aryLinkChain.length] = menu.parentLink;
    strCrumb = '<a href="' + menu.parentLink.href + '">' + menu.parentLink.innerHTML + '</a>' + strCrumbDivider + strCrumb;
    menu = menu.parentLink.parentMenu;
  }
 
  return strCrumb;
}

function showNavMenus() {
  for(var i = aryLinkChain.length-1; i >= 0; i--)
    if(aryLinkChain[i].subMenu)
      showNavMenu(aryLinkChain[i].subMenu);
}

function buildNavArray(elmNav) {
  // First we get the first child of the nav element
  var elmChild = elmNav.firstChild;
  var lastLink = null;
  var ary = new Array();

  // now we iterate through the children picking out special tags.
  while(elmChild) {
    // if the child is an anchor tag then we need to
    // capture its link to build the breadcrumbs
    // we also remember the last link seen so we
    // can handle sub menus
    if(elmChild.nodeName == 'A') {
      lastLink = elmChild;
      // we create a parentMenu property on the
      // link so we can walk backwards to build
      // our breadcrumbs
      elmChild.parentMenu = elmNav;
      // we store two values in the array
      // the first is the value of the link
      // the second is a property with a name
      // the same as the value, and this stores
      // the actual element.
      if(!ary[elmChild.href]) {
        var idx = ary.length;
        ary[idx] = elmChild.href;
        ary[elmChild.href] = elmChild;
      }
    } else if(elmChild.nodeName == 'DIV') {
      // if we have a div in our nav system is is
      // assumed to be a sub menu so we
      // assign parentLink properties and
      // assign a subMenu property to our parent
      // then we recurse into buildNavArray to
      // get an array of our children and theirs.
      // this array gets merged back into the one
      // we are creating, ignoring duplicates.
      elmChild.parentLink = lastLink;
      elmChild.parentLink.subMenu = elmChild;
      var nary = buildNavArray(elmChild);
      for(var i = 0; i < nary.length; i++) {
        if(!ary[nary[i]]) {
          var idx = ary.length;
          ary[idx] = nary[i];
          ary[nary[i]] = nary[nary[i]];
        }
      }
    }
    elmChild = elmChild.nextSibling;
  }

  return ary;
}
  
function showNavMenu(elmMenu) {
  /* this is proper but IE seems to have issues with it o nthe third level
  elmMenu.style.visibility="visible";
  elmMenu.style.position="relative";
  */
  elmMenu.style.display = "block";
}