window.onload = function() {
   instBBTMenu = new BBTMenu();
}


function BBTMenu() {

   //alert("currentPage: " + currentPage);

   // Identify <a> tag that corresponds to current page.
   // Make its parent <ul> tag visible, etc.
   // Highlight its parent <li> tag with a different background color.

   // Find all <a> tags within menu div.  First find menu div.

   var menuTags = this.getTagsByNameAndClass("div", "menu");
   var menuTag = menuTags[0];

   var aTags = menuTag.getElementsByTagName("a");
   var n_aTags = aTags.length;
   var thisPageATag;
   for (var i=0; i<n_aTags; i++) {
      aTag = aTags[i];
      if ( aTag.href.indexOf(currentPage) != -1) {
         //alert("gotit: " + aTag.href);
         thisPageATag = aTag;
         break;
      }
   }
   if (thisPageATag) {

      // Find its parent <li> tag and <li> tag's parent <ul> tag.

      var thisPageLiTag = thisPageATag.parentNode;
      var thisPageUlTag = thisPageLiTag.parentNode;

      // Make the <ul> visible, in-line with other menu items.
      // Highlight this page's <li> item specially.

      thisPageUlTag.style.visibility      = "visible";
      thisPageUlTag.style.position        = "relative";
      thisPageUlTag.style.left            = "0px";

      thisPageATag.style.backgroundColor = "#ffffff";
      thisPageATag.style.fontWeight      = "bold";
      thisPageATag.style.color           = "black";

      // Find this group's <li> tag, find it's child <b> tag, and change it
      // to down-arrow (assuming only one level of menu depth).  But only if
      // the starting <li> has class "sub".

      if (thisPageLiTag.className == "sub") {
         var thisGroupLiTag = thisPageUlTag.parentNode;
         var bTags = thisGroupLiTag.getElementsByTagName("b");
         bTags[0].innerHTML = "&#9660;";

         // Also, set all <li> tags in this group's left borders.

         var liTags = thisGroupLiTag.getElementsByTagName("li");
         var n_liTags = liTags.length;
         //alert("n_liTags: " + n_liTags);
         for (var i=0; i<n_liTags; i++){
            liTags[i].style.borderLeft = "0px";
         }
      }
   }
}

BBTMenu.prototype.getTagsByNameAndClass = function( tagName, className ) {
   var tags = [];
   var allTags = document.getElementsByTagName( tagName );
   var n_tags = allTags.length;
   for ( var i=0; i<n_tags; i++ ) {
      if ( allTags[i].className == className ) {
         tags.push( allTags[i] );
      }
   }

   return tags;
}


