if (!(typeof(addEvent)=='function')) {
  function addEvent(name,obj,f) {
    if (window.attachEvent) {
      obj.attachEvent("on"+name,f);
    } else if (window.addEventListener) {
      obj.addEventListener(name,f,false);
    }
  }
}

addEvent('load',window,function() {
  var thispage=null;
  var fullurl=window.location.protocol+'//'+window.location.host+window.location.pathname;
  var menulist=document.getElementById('menulist');
  if (!menulist) return;

  // X-platform way to figure out what element triggered an event.
  // Desirable Side-effect: disables default action.
  function getTarget(e) {
    var target=null;
    if (window.event) {
      var target=window.event.srcElement;
      window.event.cancelBubble=true;
      window.event.returnValue=false;
    } else {
      target=e.target;
      if (e.preventDefault) e.preventDefault();
      if (e.stopPropagation) e.stopPropagation();
    }
    return target;
  }

  // X-platform way to figure out the current value of a particular style
  // on a particular element.
  function getStyle(el,property) {
    var s=null;

    if (el.currentStyle) {
      s=el.currentStyle[property];
    } else if (window.getComputedStyle) {
      s=document.defaultView.getComputedStyle(el,null).getPropertyValue(property);
    }
    return s;
  }

  // Method for A elements on LI elements with a UL child.
  // Toggles visibility of the related UL. If there's an arrow, toggles that, too.
  function toggleAccordian(e) {
    TA(getTarget(e));
  }

  function TA(target) {
    if (getStyle(target.relatedul,'display') == 'none') {
      target.relatedul.style.display='block';
      if (target.relatedspan) {
        while (target.relatedspan.firstChild) target.relatedspan.removeChild(target.relatedspan.firstChild);
        target.relatedspan.appendChild(document.createTextNode('\u25bc'));
      }
    } else {
      target.relatedul.style.display='none';
      if (target.relatedspan) {
        while (target.relatedspan.firstChild) target.relatedspan.removeChild(target.relatedspan.firstChild);
        target.relatedspan.appendChild(document.createTextNode('\u25ba'));
      }
    }
  }


  // Get all the A children of menulist
  // Figure out if they belong to a LI element which has a UL child.
  // If so, write a reference to the UL element on the LI and add a click
  // event so that the visibility of the UL is toggled.
  var A=menulist.getElementsByTagName('a');

  // In IE6, an HREF value is unescaped, but window.location is not.
  // Make consistent.
  var ix=navigator.userAgent.indexOf('MSIE');
  if ((ix > -1) && (navigator.userAgent.indexOf('Opera') == -1) && (parseFloat(navigator.userAgent.substring(ix+5)) < 7)) {
    var wlp=unescape(window.location.pathname);
    fullurl=unescape(fullurl);
  } else {
    var wlp=window.location.pathname;
  }
  // alert(window.location.pathname);

  for (var i=0;i<A.length;i++) {
    if ((A[i].href==wlp) || (A[i].href==fullurl)) {
      thispage=A[i];
    }
    var li=A[i].parentNode;
    while ((li) && li.nodeName.toLowerCase() != 'li') li=li.parentNode;
    if (li) {
      var ul=li.firstChild;
      while (ul) {
        switch (ul.nodeName.toLowerCase()) {
          case 'ul':
            A[i].relatedul = ul;
            // Pursuant to BugzId: 1571:
            // addEvent('click',A[i],toggleAccordian);
            break;
          case 'span':
            A[i].relatedspan=ul;
        }
        ul=ul.nextSibling;
      }
    }
  }

  while (thispage) {
    if (thispage.nodeName.toLowerCase() == 'li') {
      var a=thispage.firstChild;
      while ((a) && (a.nodeName.toLowerCase() != 'a')) {
        a=a.nextSibling;
      }
      if ((a) && (a.relatedul)) {
        TA(a);
      }
    }
    thispage=thispage.parentNode;
  }
});