var HIDE_TIMEOUT = 500;
var hide_handle  = null;
var menus        = new Array( );
var last_shown   = "";

function M( menu_name )
{
   return menus[ menu_name ];
}

function Keep( obj )
{
   var menu = menus[ obj.id ];
   if ( typeof( menu ) == 'undefined' ) { return; }
   var lr   = menu.get( );
   menu.pop( );
}

function Leave( obj )
{
   var menu = menus[ obj.id ];
   if ( typeof( menu ) == 'undefined' ) { return; }
   menu.close( );
}

function Menu( name )
{
   this.name   = name;
   menus[ this.name ] = this;

   this.show   = function( ) {
      if ( last_shown != "" && last_shown != this.name ) {
         M( last_shown ).hide( );
      }
      var obj = this.get( );
      obj.props.visibility = "visible";
      last_shown = this.name;

      if ( hide_handle ) {
         window.clearTimeout( hide_handle );
         hide_handle = null;
      }
   };

   this.hide   = function( ) {
      var obj = this.get( );
      obj.props.visibility = "hidden";
   };

   this.get    = function( ) {
      var obj = new Object( );
      obj.handle = document.getElementById( this.name );
      obj.props  = obj.handle.style;
      return obj;
   };

   this.pop    = function( obj ) {
      this.show( );
   };

   this.close  = function( ) {
      hide_handle = window.setTimeout( 'menus[ "' + this.name + '" ].hide( )', HIDE_TIMEOUT );
   };

   function get_style(obj, css_def) {
      var str_value = "";
      if ( document.defaultView && document.defaultView.getComputedStyle ) {
         str_value = document.defaultView.getComputedStyle(obj, "").getPropertyValue(css_def);
      }
      else if ( obj.currentStyle ) {
         css_def = css_def.replace(/\-(\w)/g, function (strMatch, p1){
            return p1.toUpperCase();
         });
         str_value = obj.currentStyle[css_def];
      }
      return str_value;
   }
}
