/* [mjh] preload images: */
arrowImage          = new Image( 21, 11 );
arrowImageHover     = new Image( 21, 11 );
arrowImage.src      = s_WEBROOT + '/shared/images/nav_icn.gif';
arrowImageHover.src = s_WEBROOT + '/shared/images/nav_icn_hover.gif';

function menuItemHover( e )
{
  /* the e variable is present in Mozilla, it contains the current event */
  xEvent = ( e ) ? e : window.event;
  xObj = ( e ) ? xEvent.target : xEvent.srcElement;

  if( xObj.className != 'menuitem' 
      && xObj.className != 'menuitemHover' 
      && xObj.className != 'submenuitem' 
      && xObj.className != 'submenuitemHover' )
    return;

  /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */

  if( xObj.tagName.toUpperCase() == 'A' )
    xObj = xObj.parentNode;

  if( xObj.parentNode.childNodes.length > 2 )
  {
    /* Mozilla: */
    xLeftCol  = xObj.parentNode.childNodes[1];
    xRightCol = xObj.parentNode.childNodes[3];
  }
  else
  {
    /* IE */
    xLeftCol  = xObj.parentNode.childNodes[0];
    xRightCol = xObj.parentNode.childNodes[1];
  }

  if( xObj.className == 'menuitem' || xObj.className == 'menuitemHover'  )
  {
    xLeftCol.style.backgroundColor  = ( xEvent.type == "mouseover" ) ? "#CECF9C" : "#EFEFDE";
    xRightCol.style.backgroundColor = ( xEvent.type == "mouseover" ) ? "#CECF9C" : "#EFEFDE";
  }
  else
  {
    xLeftCol.style.backgroundColor  = ( xEvent.type == "mouseover" ) ? "#EFEFEF" : "#ffffff";
    xRightCol.style.backgroundColor = ( xEvent.type == "mouseover" ) ? "#EFEFEF" : "#ffffff";
  }
  xRightCol.childNodes[0].src     = ( xEvent.type == "mouseover" ) ? arrowImageHover.src : arrowImage.src;

  return true;
}

function menuToggle( sObjID )
{
  var xObj            = document.getElementById( sObjID );
  var bExpand         = xObj.style.display == 'none' ? true: false;
  var xCookie         = getCookie( 'MENUCOLLAPSED' );
  var sAction         = '';
  xObj.style.display  = bExpand ? 'inline' : 'none';

  lTmpList = '';

  if( xCookie )
  {
    /* cookie exists, edit it... */
    if( bExpand )
    {
      /* remove entry from list */
      for( i=0; i<listLen( xCookie, '_' ); i++ )
        if( listGetAt( xCookie, i, '_' ) != sObjID )
          lTmpList = listAppend( lTmpList, listGetAt( xCookie, i, '_' ), '_' );
    }
    else
    {
      /* add entry to list */
      lTmpList = listAppend( xCookie, sObjID, '_'  );
    }
  }
  else
  {
    /* cookie not found, create it... */
    if( !bExpand )
    {
      /* add entry to list */
      lTmpList = sObjID;
    }
  }

  /*            +~~~~~~~~~~~~~~~~~+~~~~~~~~~~~~~~~~~+~~~~~~~~~~~~~~~~~+~~~~~~~~~~~~~~~~~+~~~~~~~~~~~~~~~~~+~~~~~~~~~~~~~~~~~+ */
  /*            | name            | value           | expires         | path            | domain          | secure          | */
  /*            +~~~~~~~~~~~~~~~~~+~~~~~~~~~~~~~~~~~+~~~~~~~~~~~~~~~~~+~~~~~~~~~~~~~~~~~+~~~~~~~~~~~~~~~~~+~~~~~~~~~~~~~~~~~+ */
  deleteCookie(  'MENUCOLLAPSED',                                       '/',             'www.sigma.nl'                       );
     setCookie(  'MENUCOLLAPSED',   lTmpList,         null,             '/',             'www.sigma.nl',    false             );

  // initDebugger( sAction );
}

document.onmouseover = document.onmouseout = menuItemHover;

function initDebugger( sMessage )
{
  xDebuggerContent = document.getElementById( 'debugger' );
  xDebuggerContent.innerHTML = '';

  for( i=0; i<listLen( document.cookie, ';' ); i++ )
    xDebuggerContent.innerHTML = xDebuggerContent.innerHTML + ( listGetAt( listGetAt( document.cookie, i, ';' ), 0, '=' ) + ' = ' + listGetAt( listGetAt( document.cookie, i, ';' ), 1, '=' ) + '<br />' );
}

