/**********************************************************************************
Dynamic Tooltips
*   Copyright (C) 2001 Michael van Ouwerkerk
*   This script was released at DHTMLCentral.com
*   Visit for more great scripts!
*   This may be used and changed freely as long as this msg is intact!
*   We will also appreciate any links you could give us.
*
*   Made by Michael van Ouwerkerk
*
*   Script date: 09/09/2001 (keep this date to check versions)
*********************************************************************************/
function ht_lib_bwcheck(){ //Browsercheck (needed)
	this.ver=navigator.appVersion
	this.agent=navigator.userAgent
	this.dom=document.getElementById?1:0
	this.opera5=(navigator.userAgent.indexOf("Opera")>-1 && document.getElementById)?1:0
	this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom && !this.opera5)?1:0;
	this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom && !this.opera5)?1:0;
	this.ie7=(this.ver.indexOf("MSIE 7")>-1 && this.dom && !this.opera5)?1:0;
	this.ie4=(document.all && !this.dom && !this.opera5)?1:0;
	this.ie=this.ie4||this.ie5||this.ie6||this.ie7
	this.mac=this.agent.indexOf("Mac")>-1
	this.ns6=(this.dom && parseInt(this.ver) >= 5) ?1:0;
	this.ns4=(document.layers && !this.dom)?1:0;
	this.hoverBW=(this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.opera5)
	return this
}
var hoverBW=ht_lib_bwcheck()
// Variables to set:

fromX= 14           // How much from the actual mouse X should the description box appear?
fromY= 14           // How much from the actual mouse Y should the description box appear?
ns4center= 1        // Centering the text in ns4 doesn't work with css, use this variable instead... the value is 1 or 0
useFading= 1        // 1 for a fading effect in windows explorer 5+ and all platforms ns6, 0 for no fading effect.
animation= 1        // 1 if you want animation, 0 for no animation.
detectiontype= 1    // 1 for 'smooth' window size detection, 0 for 'flip' window size detection.
delay= 200          // The time before showing the popup, in milliseconds.


/*** There should be no need to change anything beyond this. ***/

// A unit of measure that will be added when setting the position of a layer.
var px = hoverBW.ns4||window.opera?"":"px";

if(document.layers){ //NS4 resize fix.
    scrX= window.innerWidth; scrY= window.innerHeight;
    onresize= function(){if(scrX!= window.innerWidth || scrY!= window.innerHeight){history.go(0)} };
}

// object constructor...
function makeTooltip(obj)
{
	this.doc = document;
	this.elm= document.getElementById? document.getElementById(obj):hoverBW.ie4?document.all[obj]:hoverBW.ns4?document.layers[obj]:0;
	this.css= hoverBW.ns4?this.elm:this.elm.style;
	this.wref= hoverBW.ns4?this.elm.document:this.elm;
	this.obj= obj+'makeTooltip'; eval(this.obj+'=this');
	this.w= hoverBW.ns4? this.elm.clip.width: this.elm.offsetWidth;
	this.h= hoverBW.ns4? this.elm.clip.height: this.elm.offsetHeight;
};
makeTooltip.prototype.measureIt= function(){
	this.w= hoverBW.ns4? this.elm.clip.width: this.elm.offsetWidth;
	this.h= hoverBW.ns4? this.elm.clip.height: this.elm.offsetHeight;
};
makeTooltip.prototype.writeIt= function(text){
	if (hoverBW.ns4) {this.wref.write(text); this.wref.close()}
	else this.wref.innerHTML= text;
};

// Mousemove detection
var mouseX=0,mouseY=0,setX=0,setY=0;
function getMousemove(e){
	mouseX= (hoverBW.ns4||hoverBW.ns6)? e.pageX: hoverBW.ie&&hoverBW.win&&!hoverBW.ie4? (event.clientX-2)+document.body.scrollLeft : event.clientX+document.body.scrollLeft;
	mouseY= (hoverBW.ns4||hoverBW.ns6)? e.pageY: hoverBW.ie&&hoverBW.win&&!hoverBW.ie4? (event.clientY-2)+document.body.scrollTop : event.clientY+document.body.scrollTop;
	if (hoverIsLoaded && hovering && animation) placeIt();
};
function placeIt(){
	if (detectiontype==1) setX= (mouseX+fromX+tooltip.w > screenWscrolled ? screenWscrolled-tooltip.w: mouseX+fromX) - 2;
	if (detectiontype==1) setY= mouseY+fromY+tooltip.h+20 > screenHscrolled ? screenHscrolled-tooltip.h-20: mouseY+fromY;
	if (detectiontype==0) setX= (mouseX+fromX+tooltip.w > screenWscrolled ? mouseX-fromX-tooltip.w: mouseX+fromX) - 2;
	if (detectiontype==0) setY= mouseY+fromY+tooltip.h+20 > screenHscrolled ? mouseY-fromY-tooltip.h-20: mouseY+fromY;
	if (setX<0) setX= 0;
	if (setY<0) setY= 0;
	tooltip.css.left= setX+px;
	tooltip.css.top= setY+px;

	if(!hoverBW.ns6) hideselectboxes(tooltip,setX,setY);
};

// Main hoverText function.
var hovering=false, screenWscrolled=0, screenHscrolled=0;
makeTooltip.prototype.showTimer= null;
var hoverOldWidth = 0;
function hoverText(num,width){
	if(hoverIsLoaded)
	{
		hoverOldWidth = tooltip.css.width;
		if(width)
			tooltip.css.width = width + "px";
		clearTimeout(tooltip.popTimer);
		doHoverOut();
		if (hoverBW.ns4){
			var text= '<span class="hoverTextNetscape4Style">' + (ns4center?'<center>':"") + messages[num] + (ns4center?'</center>':"") + '</span>';
			tooltip.writeIt(text);
		}
		if (!hoverBW.ns4) tooltip.writeIt(hoverMessages[num]);
		screenWscrolled= screenW + (hoverBW.ie?document.body.scrollLeft:window.pageXOffset);
		screenHscrolled= screenH + (hoverBW.ie?document.body.scrollTop:window.pageYOffset);
		hovering= true;

		/* I'm using a timeout for ie4 here, because it doesn't store the measurements quickly enough. Does anybody know why this happens? */
		if (hoverBW.ie4) setTimeout('tooltip.measureIt(); placeIt();', delay/2);
		else { tooltip.measureIt(); placeIt(); }
		if (useFading) tooltip.showTimer= setTimeout('tooltip.blendIn()', delay);
		if (!useFading) tooltip.showTimer= setTimeout('tooltip.css.visibility="visible"', delay);
    }
};

function hideselectboxes(tooltip,x,y)
{
	var selx,sely,selw,selh,i
	var w = tooltip.w;
	var h = tooltip.h;

	if(!tooltip.selBoxes)
	{
		tooltip.selBoxes=tooltip.doc.getElementsByTagName("SELECT")
	}
	var selBoxes = tooltip.selBoxes;
	if(selBoxes)
	{
		for(i=0;i<selBoxes.length;i++)
		{
			selx=0; sely=0; var selp;
			if(selBoxes[i].offsetParent)
			{
				selp=selBoxes[i];
				while(selp.offsetParent)
				{
					selp=selp.offsetParent;
					selx+=selp.offsetLeft;
					sely+=selp.offsetTop;
				}
			}
			selx+=selBoxes[i].offsetLeft;
			sely+=selBoxes[i].offsetTop;
			selw=selBoxes[i].offsetWidth;
			selh=selBoxes[i].offsetHeight;

			if(selx+selw>x && selx<x+w && sely+selh>y && sely<y+h)
			{
				if(selBoxes[i] != null && selBoxes[i].style != null && selBoxes[i].style.visibility!="hidden")
				{
					selBoxes[i].didHide=true;
					selBoxes[i].style.visibility="hidden";
				}
			}
			else if(selBoxes[i] && selBoxes[i].style && selBoxes[i].didHide)
			{
				selBoxes[i].style.visibility="visible";
				selBoxes[i].didHide = false;
			}
		}
	}
}

function showselectboxes(tooltip)
{
	var selBoxes = tooltip.selBoxes;
	if(selBoxes)
	{
		for(i=0;i<selBoxes.length;i++)
		{
			if(selBoxes[i] && selBoxes[i].style && selBoxes[i].didHide)
			{
				selBoxes[i].style.visibility="visible";
				selBoxes[i].didHide = false;
			}
		}
	}

}


// Hiding routines
makeTooltip.prototype.popTimer= null;
function hoverOut()
{
	if (hoverIsLoaded)
	{
		tooltip.css.width = hoverOldWidth;
		tooltip.popTimer= setTimeout('doHoverOut()', 30);
	}
};
function doHoverOut(){
	hovering= false;
	clearTimeout(tooltip.showTimer);
	tooltip.css.visibility= 'hidden';
	clearTimeout(tooltip.fadeTimer);
	tooltip.i= 0;
	if(!hoverBW.ns6) showselectboxes(tooltip);
};

// Measure screensize.
var scrollbarWidth= hoverBW.ns6&&hoverBW.win?14:hoverBW.ns6&&!hoverBW.win?16:hoverBW.ns4?16:0;
function measureScreen() {
	tooltip.css.top= 0+px;
	tooltip.css.left= 0+px;
	screenW= (hoverBW.ie?document.body.clientWidth:window.innerWidth) - scrollbarWidth;
	screenH= (hoverBW.ie?document.body.clientHeight:window.innerHeight);
};

// Opacity methods.
makeTooltip.prototype.blendIn= function(){
	if (hoverBW.ie && hoverBW.win && !hoverBW.ie4) {
		this.css.filter= 'blendTrans(duration=0.5)';
		this.elm.filters.blendTrans.apply();
		this.css.visibility= 'visible';
		this.elm.filters.blendTrans.play();
	}
	else {
		this.css.visibility= 'visible';
		if (!hoverBW.ns4) this.fadeIt();
	}
};
makeTooltip.prototype.step= 8;
makeTooltip.prototype.i= 0;
makeTooltip.prototype.fadeTimer= null;
makeTooltip.prototype.fadeIt= function(){
	this.i+= this.step;
	//this.css.filter= 'alpha(opacity='+this.i+')';
	this.css.MozOpacity= this.i/100;
	if (this.i<100) this.fadeTimer= setTimeout(this.obj+'.fadeIt()', 40);
	else this.i= 0;
};

// Init function...
var hoverIsLoaded= false;
function hoverTextInit(){
	//Fixing the browsercheck for opera... this can be removed if the browsercheck has been updated!!
	hoverBW.opera5 = (navigator.userAgent.indexOf("Opera")>-1 && document.getElementById)?true:false
	if (hoverBW.opera5) hoverBW.ns6 = 0

	//Extending the browsercheck to add windows platform detection.
	hoverBW.win= (navigator.userAgent.indexOf('Windows')>-1)

	tooltip= new makeTooltip('hoverTextDiv');
	tooltip.elm.onmouseover= function(){ clearTimeout(tooltip.popTimer); if(hoverBW.ns4){setTimeout('clearTimeout(tooltip.popTimer)',20)}; };
	tooltip.elm.onmouseout= doHoverOut;
	if (hoverBW.ns4) document.captureEvents(Event.MOUSEMOVE);
	document.onmousemove= getMousemove;
	measureScreen();
	if (!hoverBW.ns4) onresize= measureScreen;
	if (!hoverBW.ns4) tooltip.elm.className= 'hoverTextNormalStyle';
	if (hoverBW.ie && hoverBW.win && !hoverBW.ie4) tooltip.css.filter= 'alpha(opacity=100)'; //Preloads the windows filters.
	hoverIsLoaded= true;
};


