/* $Id: divlink.js,v 1.2 2004/03/16 21:16:01 jeroen Exp $ */

// todo:
// * test if getElementsByTagName can be replaced with xGetElementsByClassName

//
var aDivlink = new Array(  );
aDivlink[aDivlink.length] = { sElementId:"column-one",   sBgColorOut:"#56b847", sBgColorOver:"#cfe7c5" };
aDivlink[aDivlink.length] = { sElementId:"column-two",   sBgColorOut:"#0381b3", sBgColorOver:"#becfe3" };
aDivlink[aDivlink.length] = { sElementId:"column-three", sBgColorOut:"#ed393a", sBgColorOver:"#fbc8b7" };
aDivlink[aDivlink.length] = { sElementId:"column-four",  sBgColorOut:"#f6cf44", sBgColorOver:"#fceec9" };
aDivlink[aDivlink.length] = { sElementId:"column-five",  sBgColorOut:"#00a585", sBgColorOver:"#c4ded3" };

//
for ( var i = 0; i < aDivlink.length; i++ )
{
  aDivlink[aDivlink[i].sElementId] = aDivlink[i];
}

// minimum objects / methods that need to be supported to run this script
if ( ( document.getElementById && document.getElementsByTagName ) ||
   ( document.all ) )
{
  window.onload = function(  )
  {
    xAddEventListener( window, 'resize', vgGetHeight, false );
    vgSetup(  );
  }
}

//
function vgSetup(  )
{
  // temporary hack:
  var oNodeList = xGetElementsByClassName( 'divlink', null, 'DIV' );
  // instead of:
  //var oNodeList = xGetElementsByClassName( 'divlink' );
  // ...because `getElementsByTagName('*')' --as executed by
  // `xGetElementsByClassName'-- is broken (will not return anything) on
  // ie5/win.
  for ( var i = 0; i < oNodeList.length; i++ )
  {
    var oNode = xGetElementById( aDivlink[i].sElementId );
    xAddEventListener( oNodeList[i], 'mouseover', vgOver,   false );
    xAddEventListener( oNodeList[i], 'mouseout',  vgOut,    false );
    xAddEventListener( oNodeList[i], 'click',     vgClick,  false );
    oNodeList[i].sBgColorOut  = aDivlink[oNodeList[i].id].sBgColorOut;
    oNodeList[i].sBgColorOver = aDivlink[oNodeList[i].id].sBgColorOver;
/*
    var children = oNode.getElementsByTagName( 'A' );
    if ( children.length > 0 )
    {
      children[0].firstChild.nodeValue = '';
      children[0].firstChild.nodeValue = ' ';
    }
 */
  }

  vgGetHeight(  );
}

//
function vgGetHeight(  )
{
  var iMaxHeight = 0;
  for ( var i = 0; i < aDivlink.length; i++ )
  {
    var oNode = xGetElementById( aDivlink[i].sElementId );
    var iNodeHeight = xHeight( oNode );
    var iMaxHeight = ( Math.max( iMaxHeight, iNodeHeight ) );
  }

  vgSetHeight( iMaxHeight );
}

//
function vgSetHeight( iContentHeight )
{
  var iViewportHeight = xClientHeight(  );
  var iHeight = ( Math.max( iViewportHeight, iContentHeight ) );
  for ( var i = 0; i < aDivlink.length; i++ )
  {
    var oNode = xGetElementById( aDivlink[i].sElementId );
    // for IE, only change the height of floaters
    if ( oNode.currentStyle ) // ie5+/win, ie5+/unx, ie5+/mac, ie5.5+/wce
    {
      if ( oNode.currentStyle.styleFloat == 'left' ||
           oNode.currentStyle.styleFloat == 'right' )
        xHeight( oNode, iHeight );
    }
    else
      xHeight( oNode, iHeight );
  }
}

//
function vgOver( e )
{
  var oEvent = new xEvent( e );
  var oNode = oEvent.target;
  var oNodeList = oNode.getElementsByTagName( 'A' );
  if ( oNodeList.length > 0 )
  {
    var sHref = oNodeList[0].href;
    if ( sHref )
    {
      // According to the W3C spec, the cursor property can only have one
      // predefined value like [ auto | crosshair | default | ... ]. MS claims
      // that sCursor ``specifies or receives one or more of the following
      // possible values, separated by commas.'', but that doesn't seem to work
      // in ie5/win. The CSS2 value 'pointer' is not supported before ie6/win,
      // so we set it to the proprietary value 'hand' first, and override that
      // in a DOM level 2 style method if it is supported.
      oNode.style.cursor = 'hand';
      if ( oNode.style.setProperty )
        oNode.style.setProperty( 'cursor', 'pointer', null );
      xBackground( oNode, oNode.sBgColorOver );
      window.status = sHref; return true;
    }
  }
}

//
function vgOut( e )
{
  var oEvent = new xEvent( e );
  var oNode = oEvent.target;
  oNode.style.cursor = 'auto';
  xBackground( oNode, oNode.sBgColorOut );
  window.status = ''; return true;
}

//
function vgClick( e )
{
  var oEvent = new xEvent( e );
  var oNode = oEvent.target;
  var oNodeList = oNode.getElementsByTagName( 'A' );
  if ( oNodeList.length > 0 )
  {
    var sHref = oNodeList[0].href;
    if ( sHref )
      location.href = sHref;
  }
}

