//window.onload = init;

function init() {
  if (window.Event) {
    document.captureEvents(Event.MOUSEMOVE);
  }
  document.onmousemove = getXY;
}

function getXY(e) {
  scrolled = window.pageYOffset;
  scrolledDown = document.documentElement.scrollTop;
  x = (window.Event) ? e.pageX : event.clientX;
  y = (window.Event) ? e.pageY : event.clientY;

if (window.ActiveXObject && document.getElementById){y += scrolledDown};

}



function doImport(id)
{var obj = id;
  if ( !document.getElementById ) return;
  var contentObj = document.getElementById("balloon_contents");
  if ( contentObj )
  {
//    contentObj.innerHTML = '<a href="http://www.yahoo.com">My Stuff</a>';
    contentObj.innerHTML = addMapValue(obj);
  }
}

var currentBalloon = null;



function addLoadEvent(func)
{
  var oldonload = window.onload;
  if (typeof window.onload != 'function')
  {
    window.onload = func;
  }
  else
  {
    window.onload = function()
    {
      oldonload();
      func();
    }
  }
}



function hideBalloon()
{
  if ( !document.getElementById ) return;
  var balloon = document.getElementById("balloon");
  if ( balloon )
  {
    balloon.style.display = 'none';
    currentBalloon = null;
  }
  return false;
}

function displayBalloon(anImg)
{
  if ( !document.getElementById ) return;

  var imgID = anImg.getAttribute('id');
  if ( imgID == currentBalloon ) return false;
  
  currentBalloon = imgID;
  var objX = x-15;
  var objY = y-15;

  var balloon = document.getElementById("balloon");
  if ( balloon )
  {
    if ( balloon.childNodes )
    {
      while ( balloon.childNodes.length > 0 )
      {
        balloon.removeChild(balloon.childNodes[0]);
      }
    }
    var closeElt = document.createElement('img');
    closeElt.setAttribute("id","closebox");
    closeElt.setAttribute("src","http://www.worldpac.com/images/close_box.gif");
    closeElt.setAttribute("align","left");
    closeElt.setAttribute("width","14");
    closeElt.setAttribute("height","13");
    closeElt.onclick = function(){ return hideBalloon(); }
    balloon.appendChild(closeElt);

    var newElt = document.createElement('div');
    newElt.setAttribute("id","balloon_contents");
    closeElt.setAttribute("align","left");
//    newElt.setAttribute("style","overflow:auto;");
    balloon.appendChild(newElt);
	doImport(imgID);
//    balloon.style.bottom = (objY) + 'px';
    balloon.style.top = (objY-131) + 'px';
    balloon.style.left = (objX-294+40) + 'px';
    balloon.style.display = 'block';
  }
  return false;
}


function addBalloons() 
{
  if ( !document.getElementsByTagName &&
       !document.getElementById ) return;
  var nav = document.getElementById("buttons");
  if ( !nav ) return;
  var ul = nav.getElementsByTagName("ul")[0];
//  alert(ul);
  var imgElts = ul.getElementsByTagName("area");  ///chg img to area
  if ( imgElts.length > 0 )
  {
    for ( var i = 0; i < imgElts.length; i++ )
    {
      var curImg = imgElts[i];
//      curImg.onmouseover = function()
      curImg.onclick = function()
        { return displayBalloon(this); }
    }
  }
  var divElt = document.createElement('div');
  divElt.setAttribute("id", "balloon");
  document.getElementsByTagName("body")[0].appendChild(divElt);
  
}

addLoadEvent(addBalloons);
addLoadEvent(init);
