var popFollowMouse= true;	
var dom = (document.getElementById) ? true : false;
var ns5 = (!document.all && dom || window.opera) ? true: false;
var ie5 = ((navigator.userAgent.indexOf("MSIE")>-1) && dom) ? true : false;
var ie4 = (document.all && !dom) ? true : false;
var nodyn = (!ns5 && !ie4 && !ie5 && !dom) ? true : false;
var popFollowMouse= true;	
var popWidth = 0;
var offX= 5;	// how far from mouse to show tip
var offY= 5; 

var origWidth, origHeight;

// avoid error of passing event object in older browsers
if (nodyn) { event = "nope" }

var images = new Array();

var pop, popcss;

function initPop() {
	if (nodyn) return;
	pop = (ie4)? document.all['popDiv']: (ie5||ns5)? document.getElementById('popDiv'): null;
	popcss = pop.style;
	if (ie4||ie5||ns5) {	// ns4 would lose all this on rewrites
		popcss.width = popWidth+"px";
	}
	if (pop&&popFollowMouse) {
		document.onmousemove = trackMouse;
	}
}

window.onload = initPop;

var popOn = false;	// check if over tooltip link
function popup(event, image, title, alt, width, height, x, y) {
  if (!pop) return;
  popOn = true;
  frame = document.getElementById("popDiv");
  frame.style.display = "block";
  if (x >= 0 && y >= 0) {
    frame.style.top = x + "px";
    frame.style.right = y + "px";
  }           
  document.getElementById("popupTitle").innerHTML = title;
  tempImage = document.getElementById("popupImage");
  tempImage.src = image;
  tempImage.alt = alt;
  popcss.visibility='visible'
  document.onmousemove = trackMouse;
}

function popdown() {
  if (!pop) return;
  document.getElementById("popDiv").style.display = "none";
  popOn = false;
}

var mouseX, mouseY;
function trackMouse(evt) {
	standardbody=(document.compatMode=="CSS1Compat")? document.documentElement : document.body //create reference to common "body" across doctypes
	mouseX = (ns5)? evt.pageX: window.event.clientX + standardbody.scrollLeft;
	mouseY = (ns5)? evt.pageY: window.event.clientY + standardbody.scrollTop;
	if (popOn) positionPop(evt);
}

function positionPop(evt) {
	if (!popFollowMouse) {
		standardbody=(document.compatMode=="CSS1Compat")? document.documentElement : document.body
		mouseX = (ns5)? evt.pageX: window.event.clientX + standardbody.scrollLeft;
		mouseY = (ns5)? evt.pageY: window.event.clientY + standardbody.scrollTop;
	}
	// tooltip width and height
	var tpWd = (ie4||ie5)? pop.clientWidth: pop.offsetWidth;
	var tpHt = (ie4||ie5)? pop.clientHeight: pop.offsetHeight;
	// document area in view (subtract scrollbar width for ns)
	var winWd = (ns5)? window.innerWidth-20+window.pageXOffset: standardbody.clientWidth+standardbody.scrollLeft;
	var winHt = (ns5)? window.innerHeight-20+window.pageYOffset: standardbody.clientHeight+standardbody.scrollTop;
	// check mouse position against tip and window dimensions
	// and position the tooltip 
	if ((mouseX+offX+tpWd)>winWd) 
		popcss.left = mouseX-(tpWd+offX)+"px";
	else popcss.left = mouseX+offX+"px";
	if ((mouseY+offY+tpHt)>winHt) 
		popcss.top = winHt-(tpHt+offY)+"px";
	else popcss.top = mouseY+offY+"px";
	if (!popFollowMouse) t1=setTimeout("popcss.visibility='visible'",100);
}
