//Global Variables and Constants
is_safari = ((navigator.userAgent.indexOf("Safari")!=-1))?true:false;
isShowing = false;
mouseX = 0;
mouseY = 0;
ttipElement = false;

//Functions
function showTip(toolTipContent)
{
	isShowing = true;
	if(!ttipElement)
	{
		ttipElement = document.createElement("div");
		ttipElement.id = "toolTipBox";
		ttipElement.className = "toolBoxStyle";
		document.getElementsByTagName("body")[0].appendChild(ttipElement);
	}
	ttipElement.style.left = mouseX+10+"px";
  ttipElement.style.top = mouseY+10+document.body.scrollTop+"px";
  ttipElement.style.display = "block";
	ttipWindowHeight = (window.innerHeight) ? window.innerHeight : document.body.clientHeight;
  ttipElement.innerHTML = toolTipContent;
	ttipWindowScrollDistance = (!is_safari) ? ((document.documentElement.scrollTop) ? document.documentElement.scrollTop : document.body.scrollTop ) : window.pageYOffset;
	adjustVerticalPosition();
}

function adjustVerticalPosition()
{
	var ttipOvershoot = (!is_safari) ? ttipElement.offsetHeight + mouseY + 10 : ttipElement.offsetHeight + mouseY + 10 - window.pageYOffset;
	if(ttipOvershoot > ttipWindowHeight)
	{
		ttipElement.style.top = ttipWindowHeight - ttipElement.offsetHeight + ttipWindowScrollDistance + "px";
	}
	else
	{
		ttipElement.style.top = (!is_safari) ? mouseY+10+ttipWindowScrollDistance+"px" : mouseY+10+"px";
	}
}

function hideTip()
{
	if (isShowing)
	{
		ttipElement.style.display = "none";
		isShowing = false;
	}
}

function tipPosition(callingEvent)
{
  if (!callingEvent) callingEvent = window.event;
	mouseX = callingEvent.clientX;
	mouseY = callingEvent.clientY-1;
  if (isShowing)
  {
		ttipElement.style.left = mouseX+10+"px";
		adjustVerticalPosition();
  }
}

function ddrivetip(thisItem) { showTip(thisItem); }
function hideddrivetip() { hideTip(); }

document.onmousemove = tipPosition;