window.onload = initialise;

function initialise() {
 var menuArea = document.getElementById('header_top_right');
 var menuDiv = menuArea.getChildren();
 var menuList = menuDiv[0].getChildren();
 for(var ii=0; ii<menuList.length; ii++) {
  menuList[ii].firstChild.onclick = toggleMenuSub;
 }
}

function toggleMenuSub() {
 // Close all menus apart from this one
 var menuArea = document.getElementById('header_top_right');
 var menuDiv = menuArea.getChildren();
 var menuList = menuDiv[0].getChildren();
 for(var ii=0; ii<menuList.length; ii++) {
  if(menuList[ii].firstChild == this) continue;
  if(menuList[ii].firstChild.nextSibling) {
   menuList[ii].firstChild.nextSibling.className = 'headMenuSub hidden';
  }
 }
 // If this (link) has a sibling with className headMenuSub
 // then toggle that and return false
 if(this.nextSibling){
  if (this.nextSibling.className == 'headMenuSub') {
   this.nextSibling.className = 'headMenuSub hidden';
  }else {
   this.nextSibling.className = 'headMenuSub';
  }
  return false;
 }
 // Otherwise, return true
 return true;
}
