IITooltip = null;
TooltipOffX = 12;
TooltipOffY = 12;

document.onmousemove = updateIITooltip;

function updateIITooltip(e)
{
	if (IITooltip != 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 + IITooltip.offsetWidth + TooltipOffX > viewport.width + viewport.scrollX )
		{
			x = x - IITooltip.offsetWidth - TooltipOffX;
		}
		else
		{
			x = x + TooltipOffX;
		}
		
		if ( y + IITooltip.offsetHeight + TooltipOffY > viewport.height + viewport.scrollY )
		{
			if(y - IITooltip.offsetHeight - TooltipOffY > viewport.scrollY)
			{
				y = y - IITooltip.offsetHeight - TooltipOffY;
			}
			else
			{
				y = viewport.height + viewport.scrollY - IITooltip.offsetHeight;
			}
		}
		else
		{
			y = y + TooltipOffY;
		}
		
		IITooltip.style.left = x + "px";
		IITooltip.style.top = y + "px";
	}
}

function showIITooltip(id)
{
	IITooltip = document.getElementById(id);
	IITooltip.style.display = "block"
	updateIITooltip(IITooltip);
}

function hideIITooltip()
{
	IITooltip.style.display = "none";
}

function toggleIITooltip(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 - 18;
		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 - 18;
		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();
	}
	
}
