var menus = new Array();

function sortMenusArray(){

  var uls = document.getElementsByTagName("ul");

  for(var n=0; n<uls.length; n++){

    if( uls[n].className == "expandable" ){
    menus[menus.length] = new Array();

      for(var o=0; o<uls[n].getElementsByTagName("li").length; o++){
      menus[menus.length-1][o] = new Array();

        for(var p=0; p<uls[n].getElementsByTagName("li")[o].childNodes.length; p++){

          if( uls[n].getElementsByTagName("li")[o].childNodes[p].nodeName.toLowerCase() != "#text"){
            menus[menus.length-1][o][menus[menus.length-1][o].length] = uls[n].getElementsByTagName("li")[o].childNodes[p];
          }

        }
      }
    }
  }

  showHide("all", "all");

}

function showHide(menunum, linum){

  if( menunum == "all" || linum == "all" ){

    for(var n=0; n<menus.length; n++){
      for(var o=0; o<menus[n].length; o++){

        menus[n][o][1].style.display		= ( menus[n][o][1].style.display == "none" ) ? "block" : "none" ;
        menus[n][o][0].className		= ( menus[n][o][1].style.display == "none" ) ? "closed" : "open" ;

        menus[n][o][0].id = "menu"+n+"header"+o;
        menus[n][o][0].onclick = function(){

          showHide( parseInt( this.id.split("header")[0].replace(/\D/g,"") ) , parseInt( this.id.split("header")[1] ) );

        }

      }
    }

  } else {

    menus[menunum][linum][1].style.display	= ( menus[menunum][linum][1].style.display == "none" ) ? "block" : "none" ;
    menus[menunum][linum][0].className		= ( menus[menunum][linum][1].style.display == "none" ) ? "closed" : "open" ;

  }

}