   // Copyright 2005 Shing Hing Man
   // Licensed under the Apache License, Version 2.0 (the "License"); 
   // you may not use this file except in compliance with the License.
   // You may obtain a copy of the License at
   // http://www.apache.org/licenses/LICENSE-2.0 
   // Unless required by applicable law or agreed to in writing, 
   // software distributed under the License is distributed on 
   // an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 
   // express or implied. See the License for the specific language 
   // governing permissions and limitations under the License.
   

   // id for the span element that holds the tooltip
   var tooltipID="manToolTip"
   var debug=false;
   
   // Absolute position of the mouse
   var man_tooltip_xM=0;
   var man_tooltip_yM=0;
   
   // The offsets of the position of the upper corner of the tooltip
   // relative to (man_tooltip_xM, man_tooltip_yM).
   // The upper corner of the tooltip will be at
   // (man_tooltip_xM + xoffset, man_tooltip_yM + yoffset); 
   var man_tooltip_xoffset=0;
   var man_tooltip_yoffset=0;
   

   //static : indicate whether tooltip should move with mouse
   var man_tooltip_staticFlag=false;

   var man_tooltip_timeoutID;
   //var man_tooltip_timeout;
   
   // A wrapper for tooltip attributes.
   // tooltionContent is expected to be html code 
   function man_tooltip(tooltipContent, xos, yos, staticFlag,timeout){
       this.tooltipContent = tooltipContent;	   
       this.xoffset=xos;
       this.yoffset=yos;
       this.staticFlag=staticFlag;
       this.timeout=timeout;
  
       if (debug){
          alert("tootip =" + tooltipContent + "," + xos + "," + yos);
       }
   }
   
   
   // Track absolute position of the mouse. 
   function man_tooltip_track(e){
      

      if (man_isTooltipVisible() &&  man_tooltip_staticFlag){
          return;
      }
      if (!e){
	      e = window.event;
	   } 
	   
           var xyScrollOffset =man_getScrollXY();

	   // Update global position of the mouse
      
           man_tooltip_xM = e.clientX + xyScrollOffset[0];
	   man_tooltip_yM = e.clientY +  xyScrollOffset[1];
      	   
      // update position of tooltip.	   
      var tp= document.getElementById(tooltipID);
      tp.style.top=(man_tooltip_yM + man_tooltip_yoffset) + "px";
      /*tp.style.left=(man_tooltip_xM + man_tooltip_xoffset) + "px" 
      if (debug){
          window.status = man_tooltip_xM + "," +man_tooltip_yM + "," + 
            man_tooltip_xoffset + "," + man_tooltip_yoffset;     	   
     } 
     */
   }
   

// Set up new tooltip and display it.   
// This is called when the mouse is over an element with a tooltip.
// tt is a wrapper object tooltip that holds the attributes of a tooltip
function man_tooltip_gettip(tt) {	
    
 	var tp= document.getElementById(tooltipID);
	tp.innerHTML=tt.tooltipContent;
	tp.style.visibility="visible";	       

	var y = man_tooltip_yM + tt.yoffset;
        var x = man_tooltip_xM + tt.xoffset;
        if (debug){
          alert("0 get : y=" + y);
        }	     
  
	tp.style.top=y + "px";
        tp.style.left=x + "px";
         if(debug) {
            alert("1 get : tooptip top=" + tp.style.top +", tooltip left=" + 
              tp.style.left + ",tt =" + tt.tooltipContent + "," + 
              tt.xoffset + "," + tt.yoffset);
        }
	
 
	man_tooltip_xoffset = tt.xoffset;
	man_tooltip_yoffset = tt.yoffset;
        man_tooltip_staticFlag = tt.staticFlag; 
       
	 if(debug) {
            alert("2 get : tooptip top=" + tp.style.top +", tooltip left=" +  
               tp.style.left + ",tt =" + tt.tooltipContent + "," + tt.xoffset  
                + "," + tt.yoffset);
        }
	
	if ( tt.timeout > 0){
           man_tooltip_timeoutID = setTimeout("man_tooltip_reset()", tt.timeout); 
        }
}

// Clear and hide the tooltip
function man_tooltip_reset() {
  var tp= document.getElementById(tooltipID);
 
     if(debug) {
        alert("reset : tooptip top=" + tp.style.top +", tooltip left=" + tp.style.left);
     }
     tp.innerHTML="";
     tp.style.visibility="hidden";
   
     clearTimeout(man_tooltip_timeoutID);
  
}
   
// To create a span element for holding/displaying the tooltip.
// This is called from body  onload
function man_tooltip_createTooltip(){       
      if (debug){
         alert("create tooltip");
      } 
     var elem = document.createElement("span");
	 elem.setAttribute("id", tooltipID);
         elem.setAttribute("name", tooltipID);
	 document.body.appendChild(elem);
	 document.getElementById(tooltipID).style.visibility="hidden";         
	 document.getElementById(tooltipID).style.position="absolute";
}


 // A function to get the scroll offset
 function man_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 man_isTooltipVisible(){
 	var tp= document.getElementById(tooltipID);
	var visible=false;
	if(tp.style.visibility =="visible"){
           visible = true;
        }	       
        return visible;
} 


