var sMouseOver = "_lit";
var sMouseDown = "_pressed";

/******************************************************************
* Because Microsoft still has a difficult time following rules and
* standards, this method is required to retrieve an event source.
******************************************************************/
function getEventSource(e)
{
  e = e || window.event;
  return e.target || e.srcElement;
}

/**************************************************************************
* Swaps the images when the mouse moves over the object and also handles
* restoring the images when the mouse is moved away (out) from the object.
**************************************************************************/
function swapImage(e, bRestore)
{
  //Get the object that fired the event
  var evtSource = getEventSource(e);

  //Get the extension of the image  
  var sExtension = evtSource.src.substr(evtSource.src.lastIndexOf("."));

  if (bRestore)
    evtSource.src = evtSource.src.substr(0, evtSource.src.lastIndexOf(sMouseOver)) + sExtension;
  else
    evtSource.src = evtSource.src.substr(0, evtSource.src.lastIndexOf(".")) + sMouseOver + sExtension;
}

/************************************************************************
* Swaps the images for the four different mouse events.  This is done to
* fully simulate a button being pressed.
************************************************************************/
function animateButton(e)
{
  //Get the object that fired the event
  e = getEvent(e);
  var evtSource = getEventSource(e);

  //Get the extension of the image  
  var sExtension = evtSource.src.substr(evtSource.src.lastIndexOf("."));

  switch (e.type)
  {
    case "mouseover":
      evtSource.src = evtSource.src.replace(sMouseOver, "");
      evtSource.src = evtSource.src.replace(sMouseDown, "");
      evtSource.src = evtSource.src.substr(0, evtSource.src.lastIndexOf(".")) + sMouseOver + sExtension;
      break;
    case "mousedown":
      evtSource.src = evtSource.src.replace(sMouseOver, sMouseDown);
      break;
    case "mouseup":
      evtSource.src = evtSource.src.replace(sMouseDown, sMouseOver);
      break;
    case "mouseout":
      evtSource.src = evtSource.src.replace(sMouseOver, "");
      break;
  }
}