<!--

/*
############################################################
					Intructions
############################################################

1) Place this in the <head> tag...

<script src='/common/javascript/popup.js' type="text/javascript"></script>

############################################################

2) Place this at bottom of page...

<script type="text/javascript"> 
	window.onload=function(){
		init_popup();
	}
</script>

############################################################

3) Use it...

<img ONMOUSEOVER="popup('<img src=/crazyoutlinedguy.gif />',this);" ONMOUSEOUT="kill_popup();" alt='' src='/some_pic.gif' />
or...
<a href="#" ONMOUSEOVER="popup('<img src=/crazyoutlinedguy.gif />',this);" ONMOUSEOUT="kill_popup();" />Mouse over me to see picture.</a>

*/

if (document.layers){document.captureEvents(Event.MOUSEMOVE);}
document.onmousemove=mtrack;
var popup_div;
var posx=0; 
var posy=0; 
var offsetX=10; 
var offsetY=20; 
var popUp = false; 

// Build popup div to be used later.
function init_popup() {
	popup_div = document.createElement("div");
	popup_div.style.left = -1000 + 'px';
	popup_div.style.top = -1000 + 'px';
	popup_div.style.position = 'absolute';
	popup_div.innerHTML = '';
	popup_div.style.zIndex = 10;
	document.body.appendChild(popup_div);
	
}

function popup(html,e) {
	popUp = true;
	popup_div.innerHTML = html;
}

function kill_popup() {
	popUp = false;
	popup_div.style.left = -1000 + 'px';
	popup_div.style.top = -1000 + 'px';
	popup_div.innerHTML = "";
}

// track mouse when popup is popped
function mtrack(e) {
	if (popUp) {
		if (!e){ var e = window.event;}
		if (e.pageX || e.pageY) {
			posx = e.pageX;
			posy = e.pageY;
		} else if (e.clientX || e.clientY) {
			posx = e.clientX + document.body.scrollLeft;
			posy = e.clientY + document.body.scrollTop;
		}
		// adjust x if close to right side of window.
		var iSlideX = getWidth() - popup_div.childNodes[0].width;
		if (iSlideX < (posx + offsetX)){
			popup_div.style.left = iSlideX + 'px';			
		}else{
		popup_div.style.left = posx + offsetX + 'px';
		}
		// flip to top of mouse if too close to bottom.
		var iSlideY = getHeight() - popup_div.childNodes[0].height;
		if (popup_div.childNodes[0].height < (posy + offsetY)){
			popup_div.style.top = posy + offsetY - popup_div.childNodes[0].height - 35 + 'px';				
		} else {
			popup_div.style.top = posy + offsetY + 'px';
		}
	}
}

function getWidth(){
	var iWidth;
	//opera Netscape 6 Netscape 4x Mozilla 
	if (window.innerWidth){ 
		iWidth = window.innerWidth - 20; 
	}
	// IE Mozilla
	if (document.body.clientWidth) {
		iWidth = document.body.clientWidth - 15; 
	}
	return iWidth;
}

function getHeight(){
	var iHeight;
	//opera Netscape 6 Netscape 4x Mozilla 
	if (window.innerHeight){ 
		iHeight = window.innerHeight; 
	}
	// IE Mozilla
	if (document.body.clientHeight) {
		iHeight = document.body.clientHeight; 
	}
	return iHeight;
}
//-->
