   var max_menu_depth = 2;
   var current_menu = new Array(max_menu_depth);
   var hide_menu_timer = new Array(max_menu_depth);
   var animation_menu_timer = new Array(max_menu_depth);

   for( i=0; i < max_menu_depth; i++ ) {
      current_menu[i] = '';
      hide_menu_timer[i] = new Array();
      animation_menu_timer[i] = new Array();
   }
   function clear_menu( depth ) {
      for( i=depth; i < max_menu_depth;i++ ) {
         if ( current_menu[i] != '' )
            hide_menu2( current_menu[i] );
         current_menu[i] = '';
      }
   }


   function over_menu( obj ) {
      obj.style.color = '#867FB7';
   }

   function out_menu( obj ) {
      obj.style.color = '';
   }

   var menu_setup_list = new Array();
   function menu_setup( id ) {
      menu_setup_list[menu_setup_list.length] = id;
   }
   function menu_position() {
      for( i=0; i < menu_setup_list.length; i++ ) {
         var menu_holder = document.getElementById('m'+menu_setup_list[i] + '_holder');
         var menu_holder2 = document.getElementById('m'+menu_setup_list[i] + '_holder2');
         var menu = document.getElementById('m'+menu_setup_list[i]);
         var offset_icon = document.getElementById('m'+menu_setup_list[i] + '_icon');
         var depth = parseInt(menu.getAttribute('depth'));
         if ( depth > 0 ) {
            menu_holder.style.top = (offset_icon.offsetTop) + 'px';
         }
         else {
            menu_holder.style.left = offset_icon.offsetLeft - 3 + 'px';
            menu_holder2.style.left = (offset_icon.offsetLeft + menu.offsetWidth - 5 ) + 'px';
         }
      }
      for( i=0; i < menu_setup_list.length; i++ ) {
         var menu_holder = document.getElementById('m'+menu_setup_list[i] + '_holder');
         menu_holder.style.display = 'none';
      }
   }

   window.onload = menu_position;


   function show_menu( name ) {
      var menu = document.getElementById(name);
      if ( !menu ) return;
      var parent_name = menu.getAttribute('parent');
      var depth = parseInt(menu.getAttribute('depth'));

      if ( depth == 0 )
         over_menu( document.getElementById(name+'_icon'));

      if ( parent_name )
         show_menu( parent_name );

      if ( hide_menu_timer[depth][name] ) {
         window.clearTimeout( hide_menu_timer[depth][name] );
         hide_menu_timer[depth][name] = null;
      }
      if ( current_menu[depth] != name ) {
         if ( animation_menu_timer[depth][name] )
            window.clearTimeout( animation_menu_timer[depth][name] );

         for( i=depth; i < max_menu_depth; i++ )
            if ( current_menu[i] != '' )
               hide_menu2( current_menu[i] );
         current_menu[depth] = name;

         if ( menu ) {
            var menu_holder = document.getElementById(name+'_holder');
            if ( depth == 0 )
               from = parseInt( menu.style.top );
            else
               from = parseInt( menu.style.left );
            to = 0;
            menu_holder.style.display = 'block';
            var icon = document.getElementById(name + '_icon');
            if ( icon ) {
               icon.className = icon.getAttribute('class2') + ' open';
            }
            move_menu( depth, name, from, to, (to+from)/2, (to-from)/15, 'show_menu2', depth == 0 );
         }
      }
   }
   function show_menu2( name ) {
      return;
   }

   function hide_menu( name, hide_parent ) {
      var menu = document.getElementById(name);
      if ( menu ) {
         var parent_name = menu.getAttribute('parent');
         var depth = parseInt(menu.getAttribute('depth'));
         hide_menu_timer[depth][name] = window.setTimeout('hide_menu2("'+name+'");', 1000 );

         if ( hide_parent && parent_name )
            hide_menu( parent_name );
      }
   }

   function hide_menu2( name ) {
      var menu = document.getElementById(name);
      var depth = parseInt(menu.getAttribute('depth'));
      if ( depth == 0 )
         out_menu( document.getElementById(name+'_icon') );
      else {
         var icon = document.getElementById(name + '_icon');
         if ( icon )
            icon.className = icon.getAttribute( 'class2' ) + 'close';
      }
      if ( animation_menu_timer[depth][name] ) {
         window.clearTimeout( animation_menu_timer[depth][name] );
      }
      if ( hide_menu_timer[depth][name] ) {
         window.clearTimeout( hide_menu_timer[depth][name] );
         hide_menu_timer[depth][name] = null;
      }
      if ( name == current_menu[depth] )
         current_menu[depth] = '';

      var menu = document.getElementById(name);
      var menu_holder = document.getElementById(name+'_holder');
      to = parseInt(menu.getAttribute('htop'));
      from = parseInt( menu.style.top );

      menu_holder.style.zIndex = 1;
      move_menu( depth, name, from, to, (to+from)/2, (to-from)/10, 'hide_menu3', depth == 0 );
   }
   function hide_menu3( name ) {
      var menu_holder = document.getElementById(name+'_holder');
      menu_holder.style.display = 'none';
   }

   function move_menu( depth, name, current, to, half, inc, end_func, vertical ) {
      var menu = document.getElementById(name);
      current += inc;
      if ( inc > 0 ) {
         if ( current > to )
            current = to;
         if ( current > half )
            inc = Math.max( inc * 0.90, 1 );
      }
      else {
         if ( current < to )
            current = to;
         if ( current < half ) {
            inc = Math.min( inc * 0.90, -1 );
         }
      }
      if ( vertical )
         menu.style.top = current + 'px';
      else
         menu.style.left = current + 'px';

      if ( current != to ) {
         animation_menu_timer[depth][name] = window.setTimeout( 'move_menu("'+depth+'","'+name+'",'+current+','+to+','+half+','+inc+',"'+end_func+'",'+(vertical ? 'true' : 'false')+')', 7 );
      } else {
         if ( end_func ) {
            eval( end_func + '( name )' );
         }
      }
   }

