// Tool Tip II (01-June-2006)
// by Vic Phillips http://www.vicsjavascripts.org.uk
// A PopUp 'ToolTip' where Delays may be specified for both MouseOver PopUp and MouseOut PopDown.
// On PopUp the 'ToolTip' may follow the mouse with specified offsets until MouseOut.
// Alternatively the 'ToolTip' may be 'Sticky' to PopUp at a specified anchor position.
// This anchor may be the object calling the 'ToolTip' for a static 'ToolTip'.
// MouseOver of the visible 'ToolTip' may optionally retain the 'ToolTip' visible
// until MouseOut of the 'ToolTip'
// The 'ToolTip' will avoid the window edges to always be visible.
//***** Functional Code - NO NEED TO CHANGE

var zxcOOPCnt = 0;
var zxcx = 10;
var zxcy = -10;

function toolTip(tipobj, timeout, stylecname, zxcanc, tipdata){
	var tipobj=tipObject(tipobj);
	if (!tipobj.tt){
		var zxcanc=tipObject(zxcanc);
		tipobj.tt=new setToolTip(tipobj, stylecname, zxcanc, tipdata);
		if (!zxcanc){
			tipobj.onmousemove=function(event){ tipobj.tt.drag(event); }
		}
	}
	clearTimeout(tipobj.tt.to);
	tipobj.tt.tog(timeout);
}

function setToolTip(tipobj, stylecname, zxcanc, tipdata){
	this.osx=zxcx||0;
	this.osy=zxcy||0;
	this.tt = setStyle('DIV', {position:'absolute', visibility:'hidden', left:(zxcPos(tipobj)[0] + zxcx)  +'px', top:(zxcPos(tipobj)[1] + zxcy) + 'px'}, tipdata);
	document.getElementsByTagName('BODY')[0].appendChild(this.tt);
	this.tt.className = stylecname;
	
	this.ref='zxcooptt'+zxcOOPCnt++;
	window[this.ref]=this;
	this.to=null;
	this.set=true;
}

setToolTip.prototype.tog=function(timeout){
	if (this.set){ this.set=false; this.setTimeOut('show()',timeout||1); }
	else { this.set=true; this.setTimeOut('hide()',timeout||1); }
}

setToolTip.prototype.show=function(){
	setStyle(this.tt, {visibility:'visible'});
}

setToolTip.prototype.hide=function(){
	setStyle(this.tt, {visibility:'hidden'});
}

setToolTip.prototype.setTimeOut=function(zxcf,zxcd){
	this.to=setTimeout('window.'+this.ref+'.'+zxcf,zxcd);
}

setToolTip.prototype.drag=function(event){
	this.left=(zxcMse(event)[0]+this.osx);
	this.top=(zxcMse(event)[1]+this.osy);
	this.edge(zxcMse(event)[0],zxcMse(event)[1],zxcMse(event)[0],zxcMse(event)[1]);
	this.tt.style.left=(this.left)+'px';
	this.tt.style.top=(this.top)+'px';
}

setToolTip.prototype.edge=function(zxcx1,zxcy1){
	if (this.cls){ this.tt.className=this.cls[0]; }
	if (this.left<zxcWWHS()[2]){ this.left=zxcx+10; if (this.cls){ this.tt.className=this.cls[0]+this.cls[1]; } }
	else if (this.left+this.tt.offsetWidth>zxcWWHS()[0]+zxcWWHS()[2]){ this.left=zxcx1-this.tt.offsetWidth-10; if (this.cls){this.tt.className=this.cls[0]+this.cls[2]; } }
	if (this.top<zxcWWHS()[3]){ this.top=zxcy+10; if (this.cls){ this.tt.className=this.cls[0]+this.cls[3]; } }
	else if (this.top+this.tt.offsetHeight>zxcWWHS()[1]+zxcWWHS()[3]){ this.top=zxcy1-this.tt.offsetHeight-10; if (this.cls){ this.tt.className=this.cls[0]+this.cls[4]; } }
}

function zxcMse(event){
	if(!event) var event=window.event;
	if (document.all){ return [event.clientX+zxcDocS()[0],event.clientY+zxcDocS()[1]]; }
	else { return[event.pageX,zxcMseY=event.pageY]; }
}

function zxcDocS(){
	var zxcsx,zxcsy;
	if (!document.body.scrollTop){ zxcsx=document.documentElement.scrollLeft; zxcsy=document.documentElement.scrollTop; }
	else { zxcsx=document.body.scrollLeft; zxcsy=document.body.scrollTop; }
	return [zxcsx,zxcsy];
}

function tipObject(tipobj){
	if (typeof(tipobj)=='string'){ tipobj=document.getElementById(tipobj); }
	return tipobj;
}

function zxcPos(tipobj){
	zxclft=tipobj.offsetLeft;
	zxctop=tipobj.offsetTop;
	while(tipobj.offsetParent!=null){
		zxcpar=tipobj.offsetParent;
		zxclft+=zxcpar.offsetLeft;
		zxctop+=zxcpar.offsetTop;
		tipobj=zxcpar;
	}
	return [zxclft,zxctop];
}

function zxcWWHS(){
var winww,zxcwh,zxcsl,zxcst,zxcwc;
	if (window.innerHeight){
		zxcwh=window.innerHeight-20;
		zxcww=window.innerWidth-20;
		zxcsl=window.pageXOffset;
		zxcst=window.pageYOffset;
	}
	else if (document.documentElement.clientHeight){
		zxcwh=document.documentElement.clientHeight;
		zxcww=document.documentElement.clientWidth;
		zxcsl=document.documentElement.scrollLeft;
		zxcst=document.documentElement.scrollTop;
	}
	else if (document.body.clientHeight){
		zxcwh=document.body.clientHeight;
		zxcww=document.body.clientWidth;
		zxcsl=document.body.scrollLeft;
		zxcst=document.body.scrollTop;
	}
	return [zxcww,zxcwh,zxcsl,zxcst];
}

function zxcTTMseOver(zxcpid){
	var zxcp=tipObject(zxcpid)
	clearTimeout(zxcp.tt.to);
	zxcp.tt.set=false;
}

function zxcTTMseOut(zxcpid,timeout){
	var zxcp=tipObject(zxcpid)
	zxcp.tt.tog(timeout);
}

function setStyle(zxcele, setStyle, tipdata) {
	if (typeof(zxcele) == 'string') { 
		zxcele = document.createElement(zxcele); 
	}
	for (key in setStyle) { 
		zxcele.style[key] = setStyle[key]; 
	}
	if (tipdata){ 
		zxcele.innerHTML = tipdata; 
	}
	
	return zxcele;
}
