// Simple follow the mouse script
var divName = 'mydiv'; // div that is to follow the mouse
          // Y offset from mouse position used to center mouse on box

// Detect if the browser is IE or not.
// If it is not IE, we assume that the browser is NS.
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

// Temporary variables to hold mouse x-y pos.s
var tmpX = 0;
var tmpY = 0;

function stopFollow() {
	document.onmousemove = stopFollow;
			var divlocy = document.getElementById(divName).style.top
			var divloc=divlocy.replace(/px/,''); // takes off the px from the location
			var thumheight = (container_height/contents.length);
			if(divloc>-thumheight) //correct moving div to max or min position if it goes to far in wrong direction
				{
					document.getElementById(divName).style.top = -thumheight+'px';
				}
			else if(divloc<-container_height)
				{
					document.getElementById(divName).style.top = -container_height+'px';
				}
			else
				{
				}
}

// Main function to retrieve mouse x-y pos.s
function getMouseXY(e) 
{
	document.getElementById(divName).onmouseover = getMouseXY;
  	if (navigator.appName == "Microsoft Internet Explorer") { // grab the x-y pos.s if browser is IE
   	 	tmpX = event.clientX + document.body.scrollLeft
    	tmpY = event.clientY + document.body.scrollTop
  	} 
	else 
	{  // grab the x-y pos.s if browser is NS
    	tmpX = e.pageX
    	tmpY = e.pageY
  	}  
  // catch possible negative values in NS4
  	if (tmpX < 0){tmpX = 0}
  	if (tmpY < 0){tmpY = 0}  
  
  follow(tmpX, tmpY); //pass on to the follow function
}

function follow(tmpXs, tmpYs) //moves the box based on mouse position 
{ 
			var offtop = document.getElementById('cont2').offsetTop; //distance div cont2 is from top of page
	        var divlocy = document.getElementById(divName).style.top;
			var divloc=divlocy.replace(/px/,''); // takes off the px from the location
			var thumheight = (container_height/contents.length);
			var halfThumb = (thumheight/2);
			var offY = - halfThumb - offtop; //change to negative
			var positioning = (offY+tmpY-container_height);
			
	if(positioning>-thumheight) //correct moving div to max or min position if it goes to far in wrong direction
				{
					document.getElementById(divName).style.top = -thumheight+'px';
				}
			else if(positioning<-container_height)
				{
					document.getElementById(divName).style.top = -container_height+'px';
				}
			else
				{
					document.getElementById(divName).style.top = positioning+'px'; // div not passed the max or min position
				}
			//document.getElementById('cont3').innerHTML = offY;
			document.onmousemove = getMouseXY; // keeps the arrow moving after If statement
}


                    
