var mousex = 0;
var mousey = 0;

function popup(id) {
	var div = document.getElementById('popup');
	var text = popups[id];
	var offset = 27;
	div.style.display = 'block';
	var top = (mousey-100);
	var left = (mousex-120);
	var width = 250;
	var html = "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" style=\"position:absolute; top:"+top+"px; left:"+left+"px; width:"+(offset+width+offset)+"px\"><tr>";
	html += "<td style=\"background:url('images/zoom-shadow-top-left.png') no-repeat top left; width:"+offset+"px; height:"+offset+"px\"></td>";
	html += "<td style=\"background:url('images/zoom-shadow-top.png') repeat-x top left\"></td>";
	html += "<td style=\"background:url('images/zoom-shadow-top-right.png') no-repeat top left; width:"+offset+"px\"></td>";
	html += "</tr><tr>";
	html += "<td style=\"background:url('images/zoom-shadow-left.png') repeat-y top left\"></td>";
	html += "<td>";
	html += "<div style=\"width:"+width+"px; float:left; background-color:#e0f0f0; cursor:pointer;\" title=\"Klicka för att stänga\" onclick=\"popdown()\">";
	html += "<img src=\"images/zoom-close.png\" style=\"float:left; margin-left:-13px; margin-top:-13px\"/>";
	html += "<p>"+text+"</p>";
	html += "</div>";
	html += "</td>";
	html += "<td style=\"background:url('images/zoom-shadow-right.png') repeat-y top left\"></td>";
	html += "</tr><tr>";
	html += "<td style=\"background:url('images/zoom-shadow-bottom-left.png') no-repeat top left; width:"+offset+"px; height:"+offset+"px\"></td>";
	html += "<td style=\"background:url('images/zoom-shadow-bottom.png') repeat-x top left\"></td>";
	html += "<td style=\"background:url('images/zoom-shadow-bottom-right.png') no-repeat top left; width:"+offset+"px; height:"+offset+"px\"></td>";
	html += "</tr></table>";
	div.innerHTML = html;
}
function popdown(text) {
	var div = document.getElementById('popup');
	div.style.display = 'none';
}

function getMouseXY(e) // works on IE6,FF,Moz,Opera7
{
  if (!e) e = window.event; // works on IE, but not NS (we rely on NS passing us the event)

  if (e)
  { 
    if (e.pageX || e.pageY)
    { // this doesn't work on IE6!! (works on FF,Moz,Opera7)
      mousex = e.pageX;
      mousey = e.pageY;
      algor = '[e.pageX]';
      if (e.clientX || e.clientY) algor += ' [e.clientX] '
    }
    else if (e.clientX || e.clientY)
    { // works on IE6,FF,Moz,Opera7
      mousex = e.clientX + document.body.scrollLeft;
      mousey = e.clientY + document.body.scrollTop;
      algor = '[e.clientX]';
      if (e.pageX || e.pageY) algor += ' [e.pageX] '
    }  
  }
  window.status = mousex+":"+mousey;
}

function mouseInit()
{
  document.onmousemove = update; // update(event) implied on NS, update(null) implied on IE
  update();
}

function update(e)
{
  getMouseXY(e); // NS is passing (event), while IE is passing (null)
}
