<!--

// This file enables the website's collapsible dropdown
// menu.


// Handles status of all catagories
collapsibleStatusArray=new Array();
upImg = "http://bampfa.berkeley.edu/images/template/altup.gif";
downImg = "http://bampfa.berkeley.edu/images/template/altdown.gif";

// Switch from collapsed to uped
function switchMenu(iden) {

  if (collapsibleStatusArray[iden]!=1){
    show(iden);
  } else {
    hide(iden);
  }

}

function show(iden) {
  var elemStyle = document.getElementById(iden);
  var elemImg = document.getElementById(iden+"Button");
//  var elemRow = document.getElementById(iden+"Row");
  elemStyle.className="showSwitch";
  elemImg.src=downImg;
//  elemRow.style.display = "inline";
  collapsibleStatusArray[iden]=1;
}

function hide(iden) {
  var elemStyle = document.getElementById(iden);
  var elemImg = document.getElementById(iden+"Button");
//  var elemRow = document.getElementById(iden+"Row");
  elemStyle.className="hideSwitch";
  elemImg.src=upImg;
//  elemRow.style.display = "none";
  collapsibleStatusArray[iden]=0;
}

/**
  *
  * function showmenu()
  *
  * A very simple reccursive function that traverse through the sidenav with ID
  * collapsible_menu
  *
  **/

//*
function showmenu() {
  root = document.getElementById('collapsible_menu');
  if (root != null)
    traverse(root, 0);
}

function traverse(node, level) {

  var openthis = 0;

  var space = '';

  var i = 0;

//  for (i = 0; i < level; i++) {
//    space += '&emsp;';
//  }

//  document.write('<br/>'+space+'Type: '+node.nodeType+'<br/>');
//  document.write(space+'Level: '+level+'<br/>');

  if (node.nodeType == 1) { // HTML node

//  document.write(space+'Type: '+node.localName+'<br/>');

  if (node.getAttribute('href') != '' && node.getAttribute('href') != null) { // a tags

//    document.write(space+'Has href = '+node.getAttribute('href')+'<br/>');

    if (document.location.href.indexOf(node.getAttribute('href')) >= 0) { // is part of the tree
//      document.write(space+'Hit! Return: 1<br/><br/>');
//      node.setAttribute('style', 'margin-left:10px;color:#658BD2');
      return 1;
    } else { // is not part of the tree
//      document.write(space+'Miss! Return: 0<br/><br/>');
      return 0;
    }

  } else if (node.hasChildNodes()) { // not a tag, but with a child
//    children = node.childNodes;
//    document.write(space+'Children: '+node.childNodes.length+'<br/>');
    for (i = 0; i < node.childNodes.length; i++) {
//      document.write(space+'ith Child: '+i+'<br/>');
      if (node.childNodes[i] != null) {
        openthis = openthis | traverse(node.childNodes[i], level+1);
//        document.write(space+'Back to: '+node.localName+' child '+i+'<br/>');
      }
//      document.write(space+'Open: '+openthis+'<br/>');
    }
  }
  
  }

  if (openthis == 1) {
    if (node.tagName == 'UL') {
      show(node.id);
    }
  }


//  document.write(space+'Return: 0<br/><br/>');
  return openthis;

}
//*/


//-->