//-----
// tooltip.js
// 
// Ron Stewart, INEEL Center for Performance Improvment
// 
// Implementation History:
// September 2001
// 	Derived from alttxt (v1.2) by Brian Gosselin of ScriptAsylum.com; fixed
//  some of the problems with support for IE4. Opera still does not work as
//  of 09.10.2001.
//
//-----


var dofade=true;     	// ENABLES FADE-IN EFFECT FOR IE4+ AND NS6 ONLY
var center=true;     // CENTERS THE BOX UNER THE MOUSE, OTHERWISE DISPLAYS BOX TO THE RIGHT OF THE MOUSE
var centertext=false; // CENTERS THE TEXT INSIDE THE BOX. YOU CAN'T SIMPLY DO THIS VIA STYLE BECAUSE OF NS4.
                     	// OTHERWISE, TEXT IS LEFT-JUSTIFIED. 


////////////////////////////// NO NEED TO EDIT BEYOND THIS POINT //////////////////////////////////////

var NS4 = (navigator.appName.indexOf("Netscape")>=0 && !document.getElementById)? true : false;
var IE4 = (document.all && !document.getElementById)? true : false;
var IE5 = (document.getElementById && document.all)? true : false;
var NS6 = (document.getElementById && navigator.appName.indexOf("Netscape")>=0 )? true: false;
var W3C = (document.getElementById)? true : false;
var w_y, w_x, toolTipWnd, boxheight, boxwidth;
var ishover=false;
var isloaded=false;
var ieop=0;
var op_id=0;

function getwindowdims(){
w_y=(NS4||NS6)? window.innerHeight : (IE5||IE4)? document.body.clientHeight : 0;
w_x=(NS4||NS6)? window.innerWidth : (IE5||IE4)? document.body.clientWidth : 0;
}

function getboxwidth(){
if(NS4)boxwidth=(toolTipWnd.document.width)? toolTipWnd.document.width : toolTipWnd.clip.width;
if(IE5||IE4)boxwidth=(toolTipWnd.style.pixelWidth)? toolTipWnd.style.pixelWidth : toolTipWnd.offsetWidth;
if(NS6)boxwidth=(toolTipWnd.style.width)? parseInt(toolTipWnd.style.width) : parseInt(toolTipWnd.offsetWidth);
}

function getboxheight(){
if(NS4)boxheight=(toolTipWnd.document.height)? toolTipWnd.document.height : toolTipWnd.clip.height;
if(IE4||IE5)boxheight=(toolTipWnd.style.pixelHeight)? toolTipWnd.style.pixelHeight : toolTipWnd.offsetHeight;
if(NS6)boxheight=parseInt(toolTipWnd.offsetHeight);
}

function movetoolTipWnd(x,y){
if(NS4)toolTipWnd.moveTo(x,y);
if(W3C||IE4){
toolTipWnd.style.left=x+'px';
toolTipWnd.style.top=y+'px';
}}

function getpagescrolly(){
if(NS4||NS6)return window.pageYOffset;
if(IE5||IE4)return document.body.scrollTop;
}

function getpagescrollx(){
if(NS4||NS6)return window.pageXOffset;
if(IE5||IE4)return document.body.scrollLeft;
}

function writeindiv(text){
if(NS4){
toolTipWnd.document.open();
toolTipWnd.document.write(text);
toolTipWnd.document.close();
}
if(W3C||IE4)toolTipWnd.innerHTML=text;
}

//**** END UTILITY FUNCTIONS ****//

function writetxt(text){
if(isloaded){
if(text!=0){
ishover=true;
if(NS4)text='<div class="tooltip">'+((centertext)?'<center>':'')+text+((centertext)?'</center>':'')+'</div>';
writeindiv(text);
getboxheight();
if((W3C || IE4) && dofade){
ieop=0;
incropacity();
}}else{
if(NS4)toolTipWnd.visibility="hide";
if(IE4||W3C){
if(dofade)clearTimeout(op_id);
toolTipWnd.style.visibility="hidden";
}
writeindiv('');
ishover=false;
}}}

function incropacity(){
if(ieop<=100){
ieop+=25;
if(IE4 || IE5)toolTipWnd.style.filter="alpha(opacity="+ieop+")";
if(NS6)toolTipWnd.style.MozOpacity=ieop/100;
op_id=setTimeout('incropacity()', 50);
}}

function moveobj(evt){
if(isloaded && ishover){
margin=(IE4||IE5)? 1 : 23;
if(NS6)if(document.height+27-window.innerHeight<0)margin=15;
if(NS4)if(document.height-window.innerHeight<0)margin=10;
//mx=(NS4||NS6)? evt.pageX : (IE5||IE4)? event.clientX : 0;
//my=(NS4||NS6)? evt.pageY : (IE5||IE4)? event.clientY : 0;
if (NS4){
mx=evt.pageX
my=evt.pageY
}
else if (NS6){
mx=evt.clientX
my=evt.clientY
}
else if (IE5){
mx=event.clientX
my=event.clientY
}
else if (IE4){
	// RPS - 09.10.2001 
	// Why are these just set to zero?
	//mx=0
	//my=0
	mx = event.clientX;
	my = event.clientY;
}

if(NS4){
mx-=getpagescrollx();
my-=getpagescrolly();
}
xoff=(center)? mx-boxwidth/2 : mx+5;
yoff=(my+boxheight+30-getpagescrolly()+margin>=w_y)? -15-boxheight: 30;
movetoolTipWnd( Math.min(w_x-boxwidth-margin , Math.max(2,xoff))+getpagescrollx() , my+yoff+getpagescrolly());
if(NS4)toolTipWnd.visibility="show";
if(W3C||IE4)toolTipWnd.style.visibility="visible";
}}

if(NS4)document.captureEvents(Event.MOUSEMOVE);
document.onmousemove=moveobj;
window.onload=function(){
  toolTipWnd=(NS4)? document.layers['toolTipWnd'] : (IE4)? document.all['toolTipWnd'] : (W3C)? document.getElementById('toolTipWnd') : null;
  getboxwidth();
  getboxheight();
  getwindowdims();
  isloaded=true;
  if((W3C || IE4) && centertext)toolTipWnd.style.textAlign="center";
  if(W3C)toolTipWnd.style.padding='4px';
  if(IE4 || IE5 && dofade)toolTipWnd.style.filter="alpha(opacity=0)";
  }
window.onresize=getwindowdims;



