var nWidth_TT = 200;

var NS4_TT = (document.layers) ? true : false;
var IE4_TT = (document.getElementById) ? true : false;

var style_TT = true; //((NS4_TT && document.test) || IE4_TT) ? 1 : 0;

var timerID_TT = null;
var active_TT = null;

var padding_TT = 3; // < 4 recommended
var bgcolor_TT = "beige";

var borWid_TT = null; // for no border, assign null
var borCol_TT = "#0000cc";
var borSty_TT = "solid";

var str = "<style TYPE='text/css'>";
str += ".tooltip {";
str += "position: absolute;";
str += "visibility: hidden;";
str += "left: 0; top: 0;";
if (borWid_TT > 0) { // if a border is specified
  str += "border-width: " + borWid_TT + ";";
  str += "border-color: " + borCol_TT + ";";
  str += "border-style: " + borSty_TT + ";";
}
if (NS4_TT) {
  if (borWid_TT > 0 && padding_TT <= 3) {
    str += "padding: 0;";
    str += "layer-background-color: " + bgcolor_TT + ";";
  } else if (borWid_TT > 0 && padding_TT > 3) {
    str += "padding: " + (padding_TT - 3) + ";";
    str += "background-color: " + bgcolor_TT + ";";
  } else if (borWid_TT == 0) {
    str += "padding: " + padding_TT + ";";
    str += "layer-background-color: " + bgcolor_TT + ";";
  }
} else {
  str += "padding: " + padding_TT + ";";
  str += "background-color: " + bgcolor_TT + ";";
}
str += "}";
str += "</style>";

if (style_TT) {
  document.write(str);
  if (NS4_TT) window.onload = init_TT;
}

function init_TT() {
  setTimeout("window.onresize = redo_TT", 1000);
}

function redo_TT() {
  window.location.reload();
}

function makeTool(id, width, code) {
  if (!style_TT) return;
  var str = "<style TYPE='text/css'>";
  str += "#" + id + " {";
  str += "width: " + width + ";";
  str += "}";
  str += "</style>";
  str += "<DIV CLASS='tooltip' ID='" + id + "' align='left'>" + 

	code + "</DIV>";
  document.write(str);
}

var active_TT = null;

function displayTool(left, top) {
  if (NS4_TT) document.releaseEvents(Event.MOUSEMOVE);
  document.onmousemove = null;
  var whichTool = (NS4_TT) ? document[active_TT] : 
	document.getElementById(active_TT).style;
  whichTool.left = left;
  whichTool.top = top;
  whichTool.visibility = (NS4_TT) ? "show" : "visible";
}

function clearTool() {
  if (!style_TT) return;
  if (!active_TT) return;
  var whichTool = (NS4_TT) ? document[active_TT] : 
	document.getElementById(active_TT).style;
  whichTool.visibility = (NS4_TT) ? "hide" : "hidden";

  	// Handle the anchor element (replaced suffix of '_TT' with '_A'
	var anchorTool = (NS4_TT) ? document[active_TT.substr(0, active_TT.length - 3) + '_A'] : 
		document.getElementById(active_TT.substr(0, active_TT.length - 3) + '_A');
	if (anchorTool)
		(NS4_TT) ? anchorTool.color = '' : anchorTool.style.color = ''; // change anchor color

  active_TT = null;
  if (timerID_TT) clearTimeout(timerID_TT),timerID_TT=null;
  if (NS4_TT) document.releaseEvents(Event.MOUSEMOVE);
  document.onmousemove = null;
}

function activateTool(id, e) {
  if (!(NS4_TT || IE4_TT)) return;
  if (!style_TT) return;
  active_TT = id;
  
  	// Handle the anchor element (replaced suffix of '_TT' with '_A'
	var anchorTool = (NS4_TT) ? document[active_TT.substr(0, active_TT.length - 3) + '_A'] : 
		document.getElementById(active_TT.substr(0, active_TT.length - 3) + '_A');
	if (anchorTool)
		(NS4_TT) ? anchorTool.color = '#0099CC' : anchorTool.style.color = '#0099CC'; // change anchor color

  if (NS4_TT) document.captureEvents(Event.MOUSEMOVE);
  document.onmousemove = checkTool;
  checkTool(e);
}

function checkTool(e) {
  if (timerID_TT) clearTimeout(timerID_TT),timerID_TT=null;
  var left = isNav() ? e.pageX : event.clientX + document.body.scrollLeft;
  left += 20; // offset it a little...
//left = Math.min(left, (NS4_TT) ? window.innerWidth - document[active_TT].offsetWidth /*???*/: 
//	document.body.scrollWidth - (document.getElementById(active_TT).scrollWidth + 10)); // don't go off page
  var top = isNav() ? e.pageY : event.clientY + document.body.scrollTop;
  top += 20; // offset it a little...
//top = Math.min(top, (NS4_TT) ? (document[active_TT] ? window.innerHeight - document[active_TT].offsetHeight /*???*/ : 
//	top) : 
//	document.body.scrollHeight - (document.getElementById(active_TT).scrollHeight + 10)); // don't go off page
  timerID_TT = setTimeout("displayTool(" + left + ", " + 
	top + ")", 300);
}
