// Declare variables

    var mouseX = 0;
    var mouseY = 0;
    var availW = 0;
    var availH = 0;
    var deficitH = 0;
    var deficitW = 0; 

// Track the mouse

   var IE = document.all?true:false;

if (!IE) document.captureEvents(Event.MOUSEMOVE)
document.onmousemove = getMouseXY;

function getMouseXY(e) {

   // grab the x-y pos.s if browser is IE
   if (IE) { 

   mouseX = event.clientX + document.body.scrollLeft;
   mouseY = event.clientY + document.body.scrollTop;
   }

   // grab the x-y pos.s if browser is NS
   else {  
   mouseX = e.pageX;
   mouseY = e.pageY;
   }  

   if (mouseX < 0){mouseX = 0;}
   if (mouseY < 0){mouseY = 0;}  

   return true;
   }


// Show the Div

function show(idName){
   if (document.getElementById) {
   document.getElementById(idName).style.visibility = 'visible'
   } 
   else if (document.all) {
   document.all(idName).style.visibility = 'visible'
   } 
   else if (document.layers) {
   document.layers[idName].visibility = 'show'
   }
}


// Show the Div near the mouse

function mouse(idName) {

   // Get available size
   
   // Non-IE
   if( typeof( window.innerWidth ) == 'number' ) {
        availW = window.innerWidth;
        availH = window.innerHeight;
     } 
  
    // IE 6+ in 'standards compliant mode'
	else {
    if( document.documentElement &&
      ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
        availW = document.documentElement.clientWidth;
        availH = document.documentElement.clientHeight;
    } 
    
    // IE 4 compatible
	else {   
    if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
        availW = document.body.clientWidth;
        availH = document.body.clientHeight;
        }
      }
    }
  
    // Get div Size
  
    if (document.layers) {
    divWidth = document.layers[idName].document.width;
    divHeight = document.layers[idName].document.height;     
    }
	
    else if (document.all) {
    divWidth = document.all[idName].clientWidth;
    divHeight = document.all[idName].clientHeight;
    }
	
    else if (document.getElementById) {
    divHeight=document.defaultView.getComputedStyle(document.getElementById(idName),"").getPropertyValue("height")
    divHeight=eval(divHeight.substring(0,divHeight.indexOf("p")));
	
    divWidth=document.defaultView.getComputedStyle(document.getElementById(idName),"").getPropertyValue("width")
    divWidth=eval(divWidth.substring(0,divWidth.indexOf("p")));
	  
    } 
  
    // Calculate height and width deficits if not enough room for Div

    mouseY = mouseY - divHeight/2
  
    deficitH = mouseY + divHeight - availH;
    deficitW = mouseX + divWidth - availW; 
  
    // Calculate where div should be relative to mouse but not off screen
  
    if (deficitH > 0) { mouseY = mouseY - deficitH - 20; }
  
    if (mouseY < 0) { mouseY = 10 }
  
    if (deficitW > 0) { mouseX = mouseX - divWidth - 20; }
    else mouseX = mouseX + 20;
  
    if (mouseX < 0) { mouseX = 10 }
    
    
    // Position with relation to mouse LEFT
    if (document.getElementById) {
    document.getElementById(idName).style.left=mouseX;
    } 
    else if (document.all) { 
    document.getElementById(idName).style.left=mouseX;
    } 
    else if (document.layers) {
    document.layers[idName].LEFT=mouseX;
    }

    // Position with relation to mouse TOP
    if (document.getElementById) {
    document.getElementById(idName).style.top=mouseY;
    } 
    else if (document.all) {
    document.getElementById(idName).style.top=mouseY;
    } 
    else if (document.layers) {
    document.layers[idName].TOP=mouseY;
    }
 
    // Show the Div

    show(idName);
	
}

// Hide the Div

function hide(idName){
  if (document.getElementById) {
  document.getElementById(idName).style.visibility = 'hidden'
 } 
  else if (document.all) {
  document.all(idName).style.visibility = 'hidden'
 } 
  else if (document.layers) {
  document.layers[idName].visibility = 'hide'
 }
}

// End