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 o=0; o<menus[0].length; o++){
	  menus[0][o][1].style.display		= ( menus[0][o][1].style.display == "none" ) ? "block" : "none" ;
	  menus[0][o][0].className		= ( menus[0][o][1].style.display == "none" ) ? "closed_t" : "open_t" ;			

	  menus[0][o][0].id = "menu0header"+o;
	  
	  menus[0][o][0].onclick = function(){
	    showHide( parseInt( this.id.split("header")[0].replace(/\D/g,"") ) , parseInt( this.id.split("header")[1] ) );
	  }
	  
	  menus[0][o][0].onmouseover = function() {
		if( this.className != "open_t")
		  this.className = "over_t";
	  }
	  
	  menus[0][o][0].onmouseout = function() {
		if( this.className != "open_t")
		  this.className = "closed_t";
	  }
    }

    for(var n=menus.length -1; n>0; 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] ) );

        }
		menus[n][o][0].onmouseover = function() {
			if( this.className != "open")
			  this.className = "over";
		}
		menus[n][o][0].onmouseout = function() {
			if( this.className != "open")
			  this.className = "closed";
		}

      }
    }

  } else {
	if( menunum == 0 ){
      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" ) ? "over_t" : "open_t" ;		
	} 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" ) ? "over" : "open" ;		
	}
  }

}