/*************************************************************************
  This code is from Dynamic Web Coding at dyn-web.com
  Copyright 2003-5 by Sharon Paine 
  See Terms of Use at www.dyn-web.com/bus/terms.html
  regarding conditions under which you may use this code.
  This notice must be retained in the code as is!
*************************************************************************/

// adjust horizontal and vertical offsets here
// (distance from mouseover event which activates tooltip)
var offX = 4;  
var offY = 4;
var followMouse = false;  // must be turned off for hover-tip
//////////////////////////////////////
var tt = 0;
var tip=null;
var tipID = "tipDiv";
var ready= false;
var showDelay= 100;
var hideDelay= 200;

function init()
{
	if(document.createElement&&document.body&&typeof document.body.appendChild!="undefined")
	{
		if(!document.getElementById(tipID))
		{
			var el=document.createElement("DIV");
			el.id=tipID;
			document.body.appendChild(el);
		}
		ready=true;
	}
}

function dot(e,msg)
{
	clearTimer2();
	var tip = document.getElementById? document.getElementById(tipID): null;
	  if ( tip && tip.onmouseout == null )
	  {
		  tip.onmouseout = tipOutCheck;
		  tip.onmouseover = clearTimer2;
	  }
	  
	  show(e, msg);
}


function show (e,msg)
{
	if(tt)
	{
		clearTimeout(tt);
		tt=0;
	}
	if(!ready)return;
	tip=document.getElementById(tipID);
	writeTip("");
	writeTip(msg);
	positionTip(e);
	tt=setTimeout("toggleVis('"+tipID+"', 'visible')",showDelay);
	
}

function hide()
{
	if(tt)
	{
		clearTimeout(tt);
		tt=0;
	}
	tt=setTimeout("toggleVis('"+tipID+"', 'hidden')",hideDelay);
	tip=null;
}

function tipOutCheck(e) {
  // is element moused into contained by tooltip?
  var toEl = e.relatedTarget? e.relatedTarget: e.toElement;
  if ( this != toEl && !contained(toEl, this) ) hide();
}

function clearTimer2() {
  if (tt) { clearTimeout(tt); tt = 0; }
}

function writeTip(msg)
{
	if(tip&&typeof tip.innerHTML!="undefined")
	tip.innerHTML=msg;
}

function hideTip() {
  tt = setTimeout("hide()", 300);
}

function toggleVis(id,vis)
{
	var el=document.getElementById(id);
	if(el)el.style.visibility=vis;
}

function positionTip(e)
{
	if(tip&&tip.style)
	{

		var x=e.pageX?e.pageX:e.clientX;
		var y=e.pageY?e.pageY:e.clientY;
		x=x+offX;
		y=y+offY;
		tip.style.left=x+"px";
		tip.style.top=y+"px";
	}
}

function unHookHover () {
    var tip = document.getElementById? document.getElementById(tipID): null;
    if (tip) {
        tip.onmouseover = null; 
        tip.onmouseout = null;
        tip = null;
    }
}

// returns true of oNode is contained by oCont (container)
function contained(oNode, oCont) {
  if (!oNode) return; // in case alt-tab away while hovering (prevent error)
  while ( oNode = oNode.parentNode ) if ( oNode == oCont ) return true;
  return false;
}
//////////////////////////////////////
var msg = '<a href="http://">Cooooooool</a></br><a href="http://2">Cooooooool2</a>';