
/************************************ FMD MENUS ************************************/
/* Version: 1.0                                                                    */
/* Copyright (c) 2003 Flying Machine Development, All Rights Reserved              */
/* Contact: info@flyingmachinedevelopment.com                                      */
/***********************************************************************************/


  function menuMouseHndlr(e)
  {
    if(e){document.menuEvent=e;} else{document.menuEvent=event;}
  }

  function showMenu(m, x, y){var mnu=findElement(m); 
    if(document.curMenu) hideElement(document.curMenu);document.curMenu=mnu;
    if(DOM_SUPPORT && !isBrowser("IE")){mnu.addEventListener("mouseout",menuMouseHndlr,true);} 
    positionElement(mnu,x,y);
    if(mnu.style){mnu.style.zIndex = 999;}else{mnu.zIndex=999;}
    showElement(mnu);
  }

  function showMenuRelative(a, m, dx, dy){var mnu=findElement(m); 
    if(document.curMenu) hideElement(document.curMenu);document.curMenu=mnu;
    if(DOM_SUPPORT && !isBrowser("IE")){x.addEventListener("mouseout",menuMouseHndlr,true);} 
    positionElement(m,getElementLeft(a)+dx,getElementTop(a)+dy);
    if(mnu.style){mnu.style.zIndex = 999;}else{mnu.zIndex=999;}
    showElement(mnu);
  }

  function getMenuTop(mnu){
    if(!isBrowser("NS4")){var y=mnu.offsetTop;var p=mnu; 
    while(p=p.offsetParent){y+=p.offsetTop}} else{var y=mnu.y} return y;
  }

  function getMenuLeft(mnu){
    if(!isBrowser("NS4")){var x=mnu.offsetLeft;var p=mnu; 
    while(p=p.offsetParent){x+=p.offsetLeft}} else{var x=mnu.x;} return x;
  }

  function getMenuRight(mnu){
    var x=getMenuLeft(mnu) + mnu.offsetWidth;
    return x;
  }

  function getMenuBottom(mnu){
    var x=getMenuTop(mnu) + mnu.offsetHeight;
    return x;
  }

  function isInsideMenu(mnu, x, y, d){return((x-2)>getMenuLeft(mnu) && (x+2)<getMenuRight(mnu) && (y-2)>getMenuTop(mnu) && (y+2)<getMenuBottom(mnu));}

  function getMenuMouseX(){if(document.menuEvent){if(document.menuEvent.pageX) return document.menuEvent.pageX; 
    return document.menuEvent.clientX;}else{if(!isBrowser("IE")) return event.pageX; else return event.clientX;}
  }

  function getMenuMouseY(){if(document.menuEvent){if(document.menuEvent.pageY) return document.menuEvent.pageY; 
    return document.menuEvent.clientY;}else{if(!isBrowser("IE")) return event.pageY; else return event.clientY;}
  }

  function hideMenu(m){if(!isBrowser("NS4")){var mnu=findElement(m);var x=getMenuMouseX(); var y=getMenuMouseY();
    if(!isInsideMenu(mnu, x, y))hideElement(mnu);} else{hideElement(mnu);}
    if(DOM_SUPPORT && !isBrowser("IE")){mnu.removeEventListener("mouseout",menuEventHndlr,false);}
  }



/* support for menu popup at current mouse position - not currently enabled 
  function popupMouseHndlr(e)
  {
    if(e){document.popupEvent=e; else document.popupEvent=event;
  }

  function showPopupMenu(m, dx, dy){var x=findElement(m);
    if(document.curMenu) hideElement(document.curMenu);document.curMenu=m;
    if(DOM_SUPPORT){x.addEventListener("mouseout",menuMouseHndlr,true);} 
    positionElement(m,getPopupMouseX()+dx,getPopupMouseY()+dy); 
    if(x.style){x.style.zIndex = 999;}else{x.zIndex=999;}    
    showElement(m);
  }

  function getPopupMouseX(){if(document.popupEvent.pageX) return document.popupEvent.pageX; 
    return document.popupEvent.clientX;
  }

  function getPopupMouseY(){if(document.popupEvent.pageY) return document.popupEvent.pageY; 
    return document.popupEvent.clientY;
  }
*/