//static class, for efficiency reasons
function TooltipClass () {
	var CAN_DHTML = 0;var CAN_LAYERS = 0;var CAN_DOCALL = 0;var CAN_DOM = 0;
	var IS_UPP = 0;

	if (document.getElementById) {CAN_DOM = 1; CAN_DHTML = 1;}
	else if (document.all) {CAN_DOCALL = 1; CAN_DHTML = 1;}
	else { browserVersion = parseInt(navigator.appVersion); if ((navigator.appName.indexOf('Netscape') != -1) && (browserVersion == 4)) {CAN_LAYERS = 1; CAN_DHTML = 1;}}

	function gettip(id, isCss) {
		if (CAN_DOM) return isCss ? document.getElementById(id).style:document.getElementById(id);
		if (CAN_DOCALL) return isCss ? document.all[id].style: document.all[id];
		if (CAN_LAYERS) return document.layers[id];
	}
	this.gettip = gettip;

	function showOrHideTooltip (s,evt,id,timeout,is_upper) {
		if (!CAN_DHTML) return;
		IS_UPP = (is_upper) ? 1 : 0;
		var dm = gettip(id,0);
		if (!dm) return;
		if (s == 0) {
			if (!timeout || timeout == undefined) timeout = 600;
			dm.tooltipDeathSentence=true;
			setTimeout("Tooltip.hideTooltip('" + id + "', " + timeout + ")", timeout);
		}
		else {
			if (!timeout || timeout == undefined) timeout = 150;
			dm.tooltipDeathSentence=false;
			var coords = this.getScreenCoords(evt);
			setTimeout("Tooltip.showTooltip('" + id + "', " + coords.join(",") + ")", timeout);
		}
	}
	this.showOrHideTooltip = showOrHideTooltip;
	//short form for inclusion in HTML pages
	this.t = showOrHideTooltip;

	function getScreenCoords (evt) {
		var mouseX = typeof evt.pageX != "undefined" ? evt.pageX : typeof evt.clientX != "undefined" ? evt.clientX + (document.documentElement.scrollLeft ?  document.documentElement.scrollLeft : document.body.scrollLeft) : null;
		var mouseY = typeof evt.pageY != "undefined" ? evt.pageY : typeof evt.clientY != "undefined" ? evt.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop) : null;
		return new Array(mouseX, mouseY, evt.clientX, evt.clientY);
	}
	this.getScreenCoords = getScreenCoords;

	function showTooltip (id, mouseX, mouseY, clientX, clientY) {
		var dm = gettip(id,0);

		if (dm && !dm.tooltipDeathSentence) {

			var ds = gettip(id,1);
			//get visible window size
			if( typeof( window.innerWidth ) == 'number' ) {
				//Non-IE
				winwidth = window.innerWidth;
				winheight = window.innerHeight;
			} else if( document.documentElement &&
					( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
				//IE 6+ in 'standards compliant mode'
				winwidth = document.documentElement.clientWidth;
				winheight = document.documentElement.clientHeight;
			} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
				//IE 4 compatible
				winwidth = document.body.clientWidth;
				winheight = document.body.clientHeight;
			}

			var dwidth, dheight;
			if (dm.offsetWidth) {dwidth = dm.offsetWidth; dheight = dm.offsetHeight}
			else if (dm.clip.width) {dwidth = dm.clip.width; dheight = dm.clip.height}
			var ypos = mouseY + 20; var xpos = mouseX - (dwidth/4);
			if (clientX + dwidth > winwidth - 10) xpos -= dwidth / 2;
			if (xpos < 2) xpos = 2;
			if (clientY + dheight > winheight - 10) ypos -= dheight + 40;
			if (ypos < 2) ypos = 2;
			if (IS_UPP) ypos -= dheight + 40;
			if (!CAN_LAYERS) {xpos += 'px';ypos += 'px';}
			ds.left = xpos; ds.top = ypos;
			if (dm.clientWidth > 400) ds.width = '400px'; //IE5 ignores CSS max-width
			ds.visibility = "visible";
		}
	}
	this.showTooltip = showTooltip;

	function newTooltip (tip) {
		tip.onmouseover = Tooltip.tipOver;
		tip.onmouseout = Tooltip.tipOut;
		tip.tooltip_isDestroyable = true;
		return tip;
	}
	this.newTooltip = newTooltip;

	function hideTooltip (id, timeout) {
		var dm = gettip(id,0);
		if (!dm) return;
		var ds = gettip(id,1);
		if (dm.tooltipLock) return;
		if (!dm.tooltipDeathSentence) {
			setTimeout("Tooltip.hideTooltip('" + id + "', " + timeout + ")", timeout);
		}
		else {
			ds.visibility = "hidden";
			if (dm.tooltip_isDestroyable)
				if (dm.parentNode)
					dm.parentNode.removeChild(dm);
		}
	}
	this.hideTooltip = hideTooltip;

	function tipOver (obj) {
		obj.tooltipDeathSentence = false;
	}
	this.tipOver = tipOver;
	//short form for inclusion in HTML pages
	this.i = tipOver;

	function tipOut (obj) {
		obj.tooltipDeathSentence = true;
	}
	this.tipOut = tipOut;
	//short form for inclusion in HTML pages
	this.o = tipOut;

	function tipLock (id, state) {
		var dm = gettip(id,0);
		dm.tooltipLock = state;
	}
	this.tipLock = tipLock;

	function setString (id, str) {
		var dm = gettip(id,0);
		if (CAN_DOCALL || CAN_DOM){
			dm.innerHTML = "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr><td>" + str + "</td></tr></table>";
		} else if (document.layers) {
			dm.document.open();
			dm.document.write(str);
			dm.document.close();
		}
	}
	this.setString = setString;

	return this;
}
var Tooltip = new TooltipClass();
