
	var IE = document.all?true:false
	
	// If NS -- that is, !IE -- then set up for mouse capture
	if (!IE) document.captureEvents(Event.MOUSEMOVE)
	
	// Set-up to use getMouseXY function onMouseMove
	document.onmousemove = getMouseXY;
	
	var winWidth = 0
	var winHeight = 0
	// document widths

	function resetWidths(){
		winWidth = 0;
		winHeight = 0;
		if (IE){
			if (winHeight == 0){
				if (document.documentElement.clientHeight==0){
					winHeight = window.innerHeight;
				}else{
					winHeight = document.documentElement.clientHeight;
				}
			}
			if (winWidth == 0){
				winWidth = document.documentElement.clientWidth;
			}
		}else{
			winWidth = window.innerWidth;
			winHeight = window.innerHeight;
		}
	}
	resetWidths();
	
	// Temporary variables to hold mouse x-y pos.s
	var tempX = 0
	var tempY = 0
	
	window.onresize = function(){
		resetWidths();
	}
	
	// Main function to retrieve mouse x-y pos.s
	function getMouseXY(e) {
	  if (IE) { // grab the x-y pos.s if browser is IE
		tempX = event.clientX + document.documentElement.scrollLeft;
		tempY = event.clientY + document.documentElement.scrollTop;
	  } else {  // grab the x-y pos.s if browser is NS
		tempX = e.pageX;
		tempY = e.pageY;
	  }  

	  // catch possible negative values in NS4
	  if (tempX < 0){tempX = 0}
	  if (tempY < 0){tempY = 0}  
	  // show the position values in the form named Show
	  // in the text fields named MouseX and MouseY
	  return true
	}

	function makeObj(txt){
		return document.getElementById("div_" + txt);
	}
	
	function removepx(txt){
		return txt.replace("px","");
	}

	function getScrollXY() {
	  var scrOfX = 0, scrOfY = 0;
	  if( typeof( window.pageYOffset ) == 'number' ) {
		//Netscape compliant
		scrOfY = window.pageYOffset;
		scrOfX = window.pageXOffset;
	  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
		//DOM compliant
		scrOfY = document.body.scrollTop;
		scrOfX = document.body.scrollLeft;
	  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
		//IE6 standards compliant mode
		scrOfY = document.documentElement.scrollTop;
		scrOfX = document.documentElement.scrollLeft;
	  }
	  return [ scrOfX, scrOfY ];
	}

	function movePic(txt){
//		alert(winHeight);
		offset = 20;
		ymargin = 5;
		obj = makeObj(txt);
		
		// grab scroll offsets
		scroll_offsets = getScrollXY();
		scrollX = scroll_offsets[0];
		scrollY = scroll_offsets[1];
	
		// setup x, y, width, height
		width = parseFloat(removepx(obj.style.width));
		height = parseFloat(removepx(obj.style.height));
		useX = parseFloat(tempX) + offset;
		if (parseFloat(tempY) > winHeight){
			// scrolling already accounted for
			useY = parseFloat(tempY) - height + offset;
		}else{
			//useY = parseFloat(tempY) - height + scrollY + offset;
			useY = parseFloat(tempY) - height + offset;
		}
				
		// check width/height
//		if ((useY + height) > winHeight + scrollY - ymargin){
			// move it up on the screen so it shows
//			useY = winHeight + scrollY - ymargin - height;
//			if (useY < offset){
				// last resort
//				useY = offset;
//			}
//		}
		// TOO HIGH?
		if ((useY) < offset + scrollY){
			// move it up on the screen so it shows
			useY = offset + scrollY;
		}else{
			if ((useY + height) > scrollY + winHeight - offset){
				useY = scrollY + winHeight - offset - height;
			}
		}
		

		if ((useX + width) > (winWidth - scrollX)){
			// swap to left
			useX = useX - (offset*2) - width;
		}

		//set it
		obj.style.left = useX+"px";
		obj.style.top = useY+"px";
	}

	function showPopup(txt){
		obj = makeObj(txt);
		movePic(txt);
		obj.style.display="";
	}
	
	function hidePopup(txt){
		obj = makeObj(txt);
		obj.style.display="none";
	}
	

