/*
 <a href="#" onMouseOver="toolTip('Just a test', 150)" onMouseOut="toolTip()">some text here</a>
*/
function TOOLTIP()
{
//----------------------------------------------------------------------------------------------------
// Configuration
//----------------------------------------------------------------------------------------------------
	this.width = 380;					// width (pixels)
	this.height = 0;
	this.bgColor = '#E7DBCE';			// background color
	this.textColor = '#A50C10';			// text color
	this.borderColor = '#7E3642';		// border color
	this.opacity = 95;					// opacity (percent) - doesn't work with all browsers
	this.cursorDistance = 20;			// distance from cursor (pixels)

	// don't change
    this.text = '';
	this.obj = 0;
	this.sobj = 0;
	this.active = false;

// -------------------------------------------------------------------------------------------------------
// Functions
// -------------------------------------------------------------------------------------------------------
	this.create = function()
	{
		if(!this.sobj) this.init();

		var t = this.text;

		if(document.layers)
		{
			t = '<table border=1 cellspacing=4 cellpadding=4 width=' + this.width + ' bgcolor=' + this.bgColor + '><tr><td bgcolor=' + this.borderColor + '>' + t + '</td></tr></table>';
			this.sobj.document.write(t);
			this.sobj.document.close();
		}
		else
		{
			this.sobj.border = '1px solid ' + this.borderColor;
			this.setOpacity();
			if(document.getElementById)
				document.getElementById('ToolTip').innerHTML = t;
			else
				document.all.ToolTip.innerHTML = t;
		}
		this.show();
	}

	this.init = function()
	{
		if(document.getElementById)
		{
			this.obj = document.getElementById('ToolTip');
			this.sobj = this.obj.style;
		}
		else if(document.all)
		{
			this.obj = document.all.ToolTip;
			this.sobj = this.obj.style;
		}
		else if(document.layers)
		{
			this.obj = document.ToolTip;
			this.sobj = this.obj;
		}
	}

	this.show = function()
	{
		if(!this.active)
		{
			this.sobj.display = 'block';
			this.height = document.getElementById('ToolTip').offsetHeight;
			this.active = true;
		}
		var ext = (document.layers ? '' : 'px');
		var left = mouseX;
		var top = mouseY;

		if(left + this.width + this.cursorDistance > winX)
			left = mouseX - this.width - this.cursorDistance;
		else
			left += this.cursorDistance;

		if(top + this.height + this.cursorDistance > winY)
			top = winY - this.height;
		else
			top += this.cursorDistance;

		this.sobj.left = left + ext;
		this.sobj.top = top + ext;
	}

	this.hide = function()
	{
		if(this.sobj) this.sobj.display = 'none';
			this.active = false;
	}

	this.setOpacity = function()
	{
		this.sobj.filter = 'alpha(opacity=' + this.opacity + ')';
		this.sobj.mozOpacity = '.1';
		if(this.obj.filters)
			this.obj.filters.alpha.opacity = this.opacity;
		if(!document.all && this.sobj.setProperty)
			this.sobj.setProperty('-moz-opacity', this.opacity / 100, '');
	}
}

//----------------------------------------------------------------------------------------------------
// Build layer, get mouse coordinates and window width, create tooltip-object
//----------------------------------------------------------------------------------------------------
var tooltip = mouseX = mouseY = winX = winY = 0;
var prevX = 0, prevY = 0;

if(document.layers) 
{
	document.write('<layer id="ToolTip"></layer>');
	document.captureEvents(Event.MOUSEMOVE);
}
else
	document.write('<div id="ToolTip" style="position:absolute; z-index:99"></div>');

document.onmousemove = getMouseXY;

function getMouseXY(e)
{
	if(document.all)
	{
		mouseX = event.clientX + document.body.scrollLeft;
		mouseY = event.clientY + document.body.scrollTop;
	}
	else
	{
		mouseX = e.pageX;
		mouseY = e.pageY;
	}

	if ((Math.abs(prevX - mouseX) > 5) || (Math.abs(prevY - mouseY) > 5))
	{
		prevX = mouseX;
		prevY = mouseY;

		if(mouseX < 0)
			mouseX = 0;
		if(mouseY < 0)
			mouseY = 0;

		if(document.body && document.body.offsetWidth)
			winX = document.body.offsetWidth + document.body.scrollLeft - 25;
		else if(window.innerWidth)
			winX = window.innerWidth - 25;
		else
			winX = screen.width - 25;

		if(document.body && document.body.offsetHeight)
			winY = document.body.offsetHeight + document.body.scrollTop - 5;
		else if(window.innerHeight)
			winY = window.innerHeight - 5;
		else
			winY = screen.width - 5;

		if(tooltip && tooltip.active) tooltip.show();
	}
}

function toolTip(text, width, opacity)
{
	if(text)
	{
		tooltip = new TOOLTIP();
		tooltip.text = text;
		if(width)
			tooltip.width = width;
		if(opacity)
			tooltip.opacity = opacity;
		tooltip.create();
	}
	else
		if(tooltip)
			tooltip.hide();
}
