// "load" handler for the window
 YAHOO.example.onWindowLoad = function(p_oEvent) {
 // Hides submenus of the root Menu instance
    function hideSubmenus() {
       if(oMenu.activeItem) {
          var oSubmenu = oMenu.activeItem.cfg.getProperty("submenu");
          if(oSubmenu) {
                        oSubmenu.hide();
                       }
                    }
                }
// Cancels the call to "hideSubmenus"
function cancelTimer() {
   if(nTimeoutId) {
    window.clearTimeout(nTimeoutId);
                  }
                }
 // "mouseout" event handler for each submenu
function onSubmenuMouseOut(p_sType, p_aArguments, p_oMenu) {
    cancelTimer();
    nTimeoutId = window.setTimeout(hideSubmenus, 750);
}
var nTimeoutId;
// Initialize the root menu
var oMenu = new YAHOO.widget.Menu("productsandservices", { position: "static" });
// Render the root menu and corresponding submenus
 oMenu.render();
var oCommunication = oMenu.getItem(0).cfg.getProperty("submenu"),
    oPIM = oCommunication.getItem(5).cfg.getProperty("submenu"),
    oShopping = oMenu.getItem(1).cfg.getProperty("submenu"),
    oEntertainment = oMenu.getItem(2).cfg.getProperty("submenu"),
    oInformation = oMenu.getItem(3).cfg.getProperty("submenu");
// Assign event handlers
// Add a "mouseover" event handler to the root menu
oMenu.mouseOverEvent.subscribe(cancelTimer);
// Add a "mouseover" event handler to each submenu
oCommunication.mouseOverEvent.subscribe(cancelTimer);
oPIM.mouseOverEvent.subscribe(cancelTimer);
oShopping.mouseOverEvent.subscribe(cancelTimer);
oEntertainment.mouseOverEvent.subscribe(cancelTimer);
oInformation.mouseOverEvent.subscribe(cancelTimer);
// Add a "mouseout" event handler to each submenu
oCommunication.mouseOutEvent.subscribe(onSubmenuMouseOut, oCommunication, true);
oPIM.mouseOutEvent.subscribe(onSubmenuMouseOut, oPIM, true);
oShopping.mouseOutEvent.subscribe(onSubmenuMouseOut, oShopping, true);
oEntertainment.mouseOutEvent.subscribe(onSubmenuMouseOut, oEntertainment, true);
oInformation.mouseOutEvent.subscribe(onSubmenuMouseOut, oInformation, true);
// Add a "click" handler to the document
YAHOO.util.Event.addListener(document, "click", hideSubmenus);
}
// Add a "load" handler for the window
YAHOO.util.Event.addListener(window, "load", YAHOO.example.onWindowLoad);
