var currentMenu     = new Array();

var IMG_COLLAPSED   = 'url(images/collapsed.gif)';
var IMG_EXPANDED    = 'url(images/expanded1.gif)';

var PREFIX_ACTUATOR = 'actuator_';
var PREFIX_MENU     = 'menu_';
var PREFIX_INPUT    = 'input_';

var DISPLAY_NONE    = 'none';
var DISPLAY_BLOCK   = 'block';


if (!document.getElementById)
    document.getElementById = function() { return null; }


function initializeMenu ( _menuId, _open ) {

   var menuId   = _menuId;
   var actuator = document.getElementById ( PREFIX_ACTUATOR + menuId );
   var menu     = document.getElementById ( PREFIX_MENU + menuId );
   var input    = document.getElementById ( PREFIX_INPUT + menuId );

    if (menu == null || actuator == null) return;

   actuator.parentNode.style.backgroundImage = _open ? IMG_EXPANDED : IMG_COLLAPSED;
   menu.style.display = _open ? DISPLAY_BLOCK : DISPLAY_NONE;
   if (_open) {
      var i = menuId.charAt (menuId.length - 1);
      currentMenu[i] = menuId;
      if (input) {
         input.value = 1;
      }
   }


   actuator.onclick = function () {
      var i = menuId.charAt (menuId.length - 1);

      var curMenu  = document.getElementById ( PREFIX_MENU + currentMenu[i] );
      var curInput = document.getElementById ( PREFIX_INPUT + currentMenu[i] );

      if ( curMenu && menu != curMenu ) { 
         curMenu.style.display = DISPLAY_NONE;
         curMenu.parentNode.style.backgroundImage = IMG_COLLAPSED;
         curInput.value = 0;
      }
      
      if ( menu.style.display == DISPLAY_BLOCK ) {
         this.parentNode.style.backgroundImage = IMG_COLLAPSED;
         menu.style.display = DISPLAY_NONE;
         if (input) {
            input.value = 0;
         }
      }
      else {
         this.parentNode.style.backgroundImage = IMG_EXPANDED;
         menu.style.display = DISPLAY_BLOCK;
         if (input) {
            input.value = 1;
         }
      }

      currentMenu[i] = menuId;

        return false;
    }
}
