xtip = null;
TooltipOffX = 10;
TooltipOffY = -10;

document.onmousemove = updatextip;

function updatextip(e)
{
	if (xtip != null)
	{
		viewport.getAll();
		x = (document.all) ? window.event.x + document.body.scrollLeft : e.pageX;
		y = (document.all) ? window.event.y + document.body.scrollTop	: e.pageY;
		
		if ( x + xtip.offsetWidth + TooltipOffX > viewport.width + viewport.scrollX )
		{
			x = x - xtip.offsetWidth - TooltipOffX;
		}
		else
		{
			x = x + TooltipOffX;
		}
		
		if ( y + xtip.offsetHeight + TooltipOffY > viewport.height + viewport.scrollY )
		{
			if(y - xtip.offsetHeight - TooltipOffY > viewport.scrollY)
			{
				y = y - xtip.offsetHeight - TooltipOffY;
			}
			else
			{
				y = viewport.height + viewport.scrollY - xtip.offsetHeight;
			}
		}
		else
		{
			y = y + TooltipOffY;
		}
		
		xtip.style.left = x + "px";
		xtip.style.top = y + "px";
	}
}

function showxtip(id)
{
	xtip = document.getElementById(id);
	xtip.style.display = "block"
	updatextip(xtip);
	updatextip(xtip);
}

function hidextip()
{
	xtip.style.display = "none";
}

function togglextip(id)
{
	if(document.getElementById(id).style.display == "block")
	{
		document.getElementById(id).style.display = "none";
	}
	else
	{
		document.getElementById(id).style.display = "block";
	}
} 

viewport = {
	getWinWidth: function () {
		this.width = 0;
		if (window.innerWidth) this.width = window.innerWidth - 20;
		else if (document.documentElement && document.documentElement.clientWidth) 
			this.width = document.documentElement.clientWidth;
		else if (document.body && document.body.clientWidth) 
			this.width = document.body.clientWidth;
	},
	
	getWinHeight: function () {
		this.height = 0;
		if (window.innerHeight) this.height = window.innerHeight - 20;
		else if (document.documentElement && document.documentElement.clientHeight) 
			this.height = document.documentElement.clientHeight;
		else if (document.body && document.body.clientHeight) 
			this.height = document.body.clientHeight;
	},
	
	getScrollX: function () {
		this.scrollX = 0;
		if (typeof window.pageXOffset == "number") this.scrollX = window.pageXOffset;
		else if (document.documentElement && document.documentElement.scrollLeft)
			this.scrollX = document.documentElement.scrollLeft;
		else if (document.body && document.body.scrollLeft) 
			this.scrollX = document.body.scrollLeft; 
		else if (window.scrollX) this.scrollX = window.scrollX;
	},
	
	getScrollY: function () {
		this.scrollY = 0;		
		if (typeof window.pageYOffset == "number") this.scrollY = window.pageYOffset;
		else if (document.documentElement && document.documentElement.scrollTop)
			this.scrollY = document.documentElement.scrollTop;
		else if (document.body && document.body.scrollTop) 
			this.scrollY = document.body.scrollTop; 
		else if (window.scrollY) this.scrollY = window.scrollY;
	},
	
	getAll: function () {
		this.getWinWidth();
		this.getWinHeight();
		this.getScrollX();
		this.getScrollY();
	}
	
}
