var tooltip, tipcss;
var mouseX, mouseY;
var dom = (document.getElementById) ? true : false;
var ns5 = (!document.all && dom || window.opera) ? true: false;
var ie5 = ((navigator.userAgent.indexOf("MSIE")>-1) && dom) ? true : false;
var ie4 = (document.all && !dom) ? true : false;
var nodyn = (!ns5 && !ie4 && !ie5 && !dom) ? true : false;
var tipWidth= 160;
var tipFontColor= "#000000";
var tipBgColor= "#FFFFFF"; 
var tipBorderColor= "#BB00BB";
var tipBorderWidth= 3;
var tipBorderStyle= "ridge";
var tipPadding= 4;

var startStr = '<img src="';
var midStr = '" border="0"><Br>';
var endStr = '';

var origWidth, origHeight;

// avoid error of passing event object in older browsers
if (nodyn) { event = "nope" }
var t1,t2;	// for setTimeouts
var tipOn = false;	// check if over tooltip link

var tipFollowMouse= true;	
// Be sure to set tipWidth wide enough for widest image

var offX= 20;	// how far from mouse to show tip
var offY= 12; 
var tipFontFamily= "Verdana, arial, helvetica, sans-serif";
var tipFontSize= "8pt";


function trackMouse(evt) {
//	standardbody=(document.compatMode=="CSS1Compat")? document.documentElement : document.body //create reference to common "body" across doctypes
	mouseX = (ns5)? evt.pageX: window.event.clientX + document.body.scrollLeft;
	mouseY = (ns5)? evt.pageY: window.event.clientY + document.body.scrollTop;
	if (tipOn) positionTip(evt);
}


function doTooltip(srcimg,txtimg,evt,num) {

	if (!tooltip) return;
	if (t1) clearTimeout(t1);	if (t2) clearTimeout(t2);
	tipOn = true;
	// set colors if included in messages array
	curBgColor = tipBgColor;
	curFontColor = tipFontColor;
	
	//if (ie4||ie5||ns5) {
		var tip = startStr + srcimg + midStr + '<span style="font-family:' + tipFontFamily + '; font-size:' + tipFontSize + '; color:' + curFontColor + ';">' + txtimg + '</span>';

		tipcss.backgroundColor = curBgColor;
		tooltip.innerHTML = tip;
try
{
	 	tooltip.innerHTML = tip;
	}
	catch(ex)
	{
		alert(ex.message);
	}
	if (!tipFollowMouse) 
		positionTip(evt);
	else 
		{
//			tipcss.visibility='visible';
		t1=setTimeout("tipcss.visibility='visible'",100);
		//alert('ok');
	}
}

function positionTip(evt) {
//	if (!tipFollowMouse) {
	//	standardbody=(document.compatMode=="CSS1Compat")? document.documentElement : document.body
		mouseX = (ns5)? evt.pageX: window.event.clientX + document.body.scrollLeft;
		mouseY = (ns5)? evt.pageY: window.event.clientY + document.body.scrollTop;
//	}

	// tooltip width and height
	var tpWd = (ie4||ie5)? tooltip.clientWidth: tooltip.offsetWidth;
	var tpHt = (ie4||ie5)? tooltip.clientHeight: tooltip.offsetHeight;
	// document area in view (subtract scrollbar width for ns)
	var winWd = (ns5)? window.innerWidth-20+window.pageXOffset: document.body.clientWidth+document.body.scrollLeft;
	var winHt = (ns5)? window.innerHeight-20+window.pageYOffset: document.body.clientHeight+document.body.scrollTop;
	// check mouse position against tip and window dimensions
	// and position the tooltip 
	if ((mouseX+offX+tpWd)>winWd) 
		tipcss.left = mouseX-(tpWd+offX)+"px";
	else tipcss.left = mouseX+offX+"px";
	if ((mouseY+offY+tpHt)>winHt) 
		tipcss.top = winHt-(tpHt+offY)+"px";
	else tipcss.top = mouseY+offY+"px";

window.status = "POS: "+mouseX+":"+mouseY+" == "+tipcss.left+":"+tipcss.top;
	if (!tipFollowMouse) {
		// t1=setTimeout("tipcss.visibility='visible'",100);
		tipcss.visibility='visible';
	}
}

function hideTip() {
	if (!tooltip) return;
	// t2=setTimeout("tipcss.visibility='hidden'",100);
	tipcss.visibility='hidden';
	tipOn = false;
}


function initTip() {
	if (nodyn) return;
	tooltip = (ie4)? document.all['tipDiv']: (ie5||ns5)? document.getElementById('tipDiv'): null;
	tipcss = tooltip.style;
	if (ie4||ie5||ns5) {	// ns4 would lose all this on rewrites
		tipcss.width = tipWidth+"px";
		tipcss.fontFamily = tipFontFamily;
		tipcss.fontSize = tipFontSize;
		tipcss.color = tipFontColor;
		tipcss.backgroundColor = tipBgColor;
		tipcss.borderColor = tipBorderColor;
		tipcss.borderWidth = tipBorderWidth+"px";
		tipcss.padding = tipPadding+"px";
		tipcss.borderStyle = tipBorderStyle;
	}
	if (tooltip&&tipFollowMouse) {
		document.onmousemove = trackMouse;
	}
}
