function init() {
////	DISABLED 2010-03-11 John Sanders
//  if (window.Event) {
//    document.captureEvents(Event.mousemove);
//  }
  document.onmousemove = getMouseXY;
}

function getMouseXY(e) {
	ev = e || window.event;
	IE = document.all?true:false;
	if(IE) {
		x = ev.clientX;
		y = ev.clientY;
		if (window.ActiveXObject && document.getElementById){y += document.documentElement.scrollTop};
	} else {
		x = ev.pageX;
		y = ev.pageY;
	}
	
////	DISABLED 2010-03-11 John Sanders
//	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};

}

// grab the locations by id (id = state initial, such as CA for California)
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;


////	DISABLED 2010-03-11 John Sanders
////	I simplified the window.onload event at the bottom, and we don't need this anymore.
//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;
}

// pops open a balloon when the user clicks on an <area> in the worldpac location <map>
function displayBalloon(anImg)
{
  if ( !document.getElementById ) return;

  var imgID = anImg.getAttribute('id');
  if ( imgID == currentBalloon ) return false;
  
  currentBalloon = imgID;
  var objX = x-8;
  var objY = y-25;

  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;
}


//	Create onclick event handler for each <area> on the worldpac location <map>
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);
  
}

//	Run these functions when the page has loaded
window.onload = function() {
	addBalloons();
	init();
}

////	DISABLED 2010-03-11 John Sanders
//addLoadEvent(addBalloons);
//addLoadEvent(init);
