//==========================================
// initialization
//==========================================

if(ns){doc = "document."; sty = ""}
if(ie){doc = "document.all."; sty = ".style"}
if(ff){doc = "document.getElementById('"; sty = "').style"}

var tooltipDiv = "ToolTip"
var tooltipTable = "ToolTipTable"
var standTooltipTitle = "Info"

var initialize = 0
var Ex, Ey, topColor, subColor, ContentInfo

if(ie){
Ex = "event.x"
Ey = "event.y"

topColor = "#FFFFE2"
subColor = "#FFFFE1"
}

if(ns){
Ex = "e.pageX"
Ey = "e.pageY"
window.captureEvents(Event.MOUSEMOVE)
window.onmousemove=overhere

topColor = "#FFFFE2"
subColor = "#FFFFF1"
}

if(ff){
Ex = "e.pageX"
Ey = "e.pageY"
window.captureEvents(Event.MOUSEMOVE)
document.onmousemove=overhere

topColor = "#FFFFE2"
subColor = "#FFFFF1"
}
//==========================================
// Show tooltip
//==========================================

function ShowTooltip(content, title)
{
	if (title == null)
		title = standTooltipTitle;
	EnterContent(tooltipDiv, title, content)
	Activate();
}

//==========================================
// Move tooltip
//==========================================

function MoveToolTip(layerName, FromTop, FromLeft, e)
{
	if(ie)
	{
		eval(doc + layerName + sty + ".top = "  + (eval(FromTop) + document.body.scrollTop))
	}
	if(ns)
	{
		eval(doc + layerName + sty + ".top = "  +  eval(FromTop))
	}
	if(ff)
	{
		eval(doc + layerName + sty + ".top = "  +  eval(FromTop))
	}
	eval(doc + layerName + sty + ".left = " + (eval(FromLeft) + 15));
	
	if (initialize)
	{
	OverflowX(layerName, e);	
	OverflowY(layerName, e);	
	}
}

//==========================================
// Replace tooltip content
//==========================================

function ReplaceContent(layerName)
{
	if(ie)
	{
		document.all[layerName].innerHTML = ContentInfo
	}
	if(ns)
	{
		with(document.layers[layerName].document) 
		{ 
			open(); 
			write(ContentInfo); 
			close(); 
		}
	}
	if(ff)
	{
		document.getElementById(layerName).innerHTML = ContentInfo
	}
}

//==========================================
// Activation flag set to active
//==========================================

function Activate()
{
	initialize = 1;
}

//==========================================
// Activation flag set to inactive
//==========================================

function deActivate()
{
	initialize = 0; 
}

//==========================================
// Overhere
//==========================================

function overhere(e)
{
 	if(initialize)
	{
		MoveToolTip(tooltipDiv, Ey, Ex, e)
		eval(doc + tooltipDiv + sty + ".visibility = 'visible'")
	}
	else
	{
		MoveToolTip(tooltipDiv, 0, 0)
		eval(doc + tooltipDiv + sty + ".visibility = 'hidden'")
	}
}

//==========================================
// EnterContent
//==========================================

function EnterContent(layerName, TTitle, TContent){

ContentInfo = '<table id="' + tooltipTable + '" border="0" width="150" cellspacing="0" cellpadding="0">'+
'<tr><td width="100%" bgcolor="#000000">'+

'<table border="0" width="100%" cellspacing="1" cellpadding="0">'+
'<tr><td width="100%" bgcolor='+topColor+'>'+

'<table border="0" width="90%" cellspacing="0" cellpadding="0" align="center">'+
'<tr><td width="100%">'+

'<font class="tooltiptitle">&nbsp;'+TTitle+'</font>'+

'</td></tr>'+
'</table>'+

'</td></tr>'+

'<tr><td width="100%" bgcolor='+subColor+'>'+

'<table border="0" width="90%" cellpadding="0" cellspacing="1" align="center">'+

'<tr><td width="100%">'+

'<font class="tooltipcontent">'+TContent+'</font>'+

'</td></tr>'+
'</table>'+

'</td></tr>'+
'</table>'+

'</td></tr>'+
'</table>';


ReplaceContent(layerName)

}

//==========================================
// GetTooltipWidth
//==========================================

function GetTooltipWidth()
{
	var element = GetById(tooltipTable);
	if (element)
		return parseInt(element.width);
	else
		return null;
}

//==========================================
// GetTooltipHeight
//==========================================

function GetTooltipHeight()
{
	//temp yet: constant
	return 50;
}

//==========================================
// OverflowX
//==========================================

function OverflowX(layerName, e)
{
	var winx = GetWinWidth();
	var ttwidth = GetTooltipWidth();
	if ((eval(Ex) + ttwidth) > winx)
		eval(doc + layerName + sty + ".left = " + (eval(Ex) - ttwidth))
}

//==========================================
// OverflowX
//==========================================

function OverflowY(layerName, e)
{
	var winy = GetWinHeight();
	var ttheight = GetTooltipHeight();
	if ((eval(Ey) + ttheight) > winy)
		eval(doc + layerName + sty + ".top = " + (eval(Ey) - ttheight))
}

