/* PopupDiv. Written by Paul Hamer.

  This script must be included at the beginning of the HTML file. The script allows
  two types of popup.

  1: Popup with a fixed position.

     Popup declaration:
      <div id="myPopName" style="position: absolute; visibility: hidden; left: 100px; top: 200px;"></div>

     Calling:
      <a href="javascript:;" onMouseOver="showPopupAtMouse(myPopName,event)"
                                onMouseOut="hidePopup(myPopName)">Click me</a>

  2: Popup which moves along with the mousepointer.

     Popup declaration:
      <div id="myPopName" style="position: absolute; visibility: hidden;"></div>

     Calling:
      <a href="javascript:;" onMouseOver="showPopup(myPopName)"
                                onMouseOut="hidePopup(myPopName)">Click me</a>

*/

// Detect browser
NS4 = (document.layers) ? 1 : 0;
IE4 = (document.all) ? 1 : 0;
if ((IE4) && (navigator.userAgent.indexOf('MSIE 5')>0)) {
  IE5 = true;
} else {
  IE5 = false;
}

// Activate the mouseMove function
document.onmousemove = mouseMove;
if (document.layers) document.captureEvents(Event.MOUSEMOVE);

// No popup active
activePop = null;

function showPopupAtMouse(popObj,evt) {
  div = getDiv(popObj);
  activePop = popObj;
  if (NS4) {
    x = evt.x + 10;
    y = evt.y + 10;
  } else if (IE5) {
    x = event.x + document.body.scrollLeft + 10;
    y = event.y + document.body.scrollTop + 10;
  } else if (IE4) {
    x = event.x + 10;
    y = event.y + 10;
  }
  if (x<5) x=5;
  if (y<5) y=5;
  if (NS4) {
    div.left = x;
    div.top = y;
    div.visibility = "show";
  } else if (IE4) {
    div.style.pixelLeft = x;
    div.style.pixelTop = y;
    div.style.visibility = "visible";
  }
}

function showPopup(popObj) {
  div = getDiv(popObj);
  if (NS4) {
    div.visibility = "show";
  } else if (IE4) {
    div.style.visibility = "visible";
  }
}

function hidePopup(popObj) {
  div = getDiv(popObj);
  activePop = null;
  if (NS4) {
    div.visibility = "hide";
  } else if (IE4) {
    div.style.visibility = "hidden";
  }
}

function getDiv(popObj) {
  NS4 = (document.layers) ? 1 : 0;
  IE4 = (document.all) ? 1 : 0;
  if (NS4) {
    div = document.layers[popObj.name];
  } else if (IE4) {
    div = document.all[popObj.id];
    IE5 = false;
    if (navigator.userAgent.indexOf('MSIE 5')>0) IE5 = true;
  } else {
    document.open();
    document.writeln("Error: Your browser does not support layers, get NS4 or IE4.");
    document.close();
  }
  return div;
}

function mouseMove(evt) {
  if (activePop != null) {
    div = getDiv(activePop);
    if (NS4) {
      x = evt.x + 10;
      y = evt.y + 10;
    } else if (IE5) {
      x = event.x + document.body.scrollLeft + 10;
      y = event.y + document.body.scrollTop + 10;
    } else if (IE4) {
      x = event.x + 10;
      y = event.y + 10;
    }
    if (NS4) {
      div.left = x;
      div.top = y;
    } else if (IE4) {
      div.style.pixelLeft = x;
      div.style.pixelTop = y;
    }
  }
}
