//open menu with given ID
function openMenu(id) {
  //if the menu code is ready
  if(um.ready) {
    //find co-ordinates of link object
    var linkObj = document.getElementById("button_" + id);
    var coords = {
      'x' : um.getRealPosition(linkObj,'x'),
      'y' : um.getRealPosition(linkObj,'y')
    };
    //increase y-position to place below the top of the button
    coords.y += linkObj.offsetHeight + 2;
    //increase x-position to place it below the link
    //coords.x += linkObj.offsetWidth;
    //activate menu at returned co-ordinates
    um.activateMenu("menu_" + id, coords.x + 'px', coords.y + 'px');
  }
}

//close menu with given ID
function closeMenu(id) {
  //if the menu code is ready
  if(um.ready) {
    //deactive menu
    um.deactivateMenu("menu_" + id);
  }
}

function customEventHandler(eventObject, eventCode) {
  if (eventCode == "060" || eventCode == "070") {
    var id = eventObject.parentNode.id.replace("menu_", "");
    var linkObj = document.getElementById("button_" + id);
    switch (eventCode) {
      //MENU OPEN EVENT
      case "060":
	  	if (linkObj != null) {
        	linkObj.className = linkObj.className.replace('nav-btn-menu-closed', 'nav-btn-menu-open');
		}
        break;
      //MENU CLOSE EVENT
      case "070":
	    if (linkObj != null) {
        	linkObj.className = linkObj.className.replace('nav-btn-menu-open', 'nav-btn-menu-closed');
		}
        break;
    }
  }
}

um.addReceiver(customEventHandler, "");
