﻿if(!BarTab)
	new BarTab();
	
// Class: ToolTip
BarTab.ToolTip = function()
{
	// Tooltip disappear delay (in miliseconds)
	BarTab.ToolTip.DisappearDelay = 0;
	
	// Vertical offset of tooltip from anchor link, if any
	BarTab.ToolTip.VerticalOffset = -5;
	
	// 0 or 1, to disable or enable the arrow image
	BarTab.ToolTip.EnableArrowHead = 1;
	
	// Path to down and up arrow images
	BarTab.ToolTip.ArrowHeadImg = ["../../App_Themes/Tooltip/Img/arrowdown.gif", "../../App_Themes/Tooltip/Img/arrowup.gif"];
	
	// Height of arrow image (amount to reveal)
	BarTab.ToolTip.ArrowHeadHeight = 11;
	
	// Set browser type
	BarTab.ToolTip.IE = document.all;
	BarTab.ToolTip.NS6 = document.getElementById&&!document.all;
	BarTab.ToolTip.VerticalOffset = (BarTab.ToolTip.EnableArrowHead)? BarTab.ToolTip.VerticalOffset + BarTab.ToolTip.ArrowHeadHeight : BarTab.ToolTip.VerticalOffset;
	
	// Tooltip arrow object
	BarTab.ToolTip.Arrow = null;
	
	// Tooltip object container
	BarTab.ToolTip.DropMenuObj = null;
	
	BarTab.ToolTip.DelayToHide = null;
	
	
	// Initilise tooltip
	BarTab.ToolTip.Init = function()
	{
		try
		{
			if (BarTab.ToolTip.EnableArrowHead)
			{
				BarTab.ToolTip.Arrow = document.createElement("IMG");
				BarTab.ToolTip.Arrow.setAttribute("src", BarTab.ToolTip.ArrowHeadImg[0]);
				BarTab.ToolTip.Arrow.setAttribute("id", "arrowhead");
				document.body.appendChild(BarTab.ToolTip.Arrow);
			}

			BarTab.ToolTip.DropMenuObj = document.createElement("DIV");
			BarTab.ToolTip.DropMenuObj.setAttribute("id", "divTabTabTooltip");
			BarTab.ToolTip.DropMenuObj.className = "balloonstyle";
			document.body.appendChild(BarTab.ToolTip.DropMenuObj);
		}
		catch(e){}
	};
	
	BarTab.ToolTip.GetPositionOffset = function(what, offsettype)
	{
		try
		{
			var totaloffset = (offsettype=="left")? what.offsetLeft : what.offsetTop;
			var parentEl = what.offsetParent;
			while (parentEl!=null)
			{
				totaloffset = (offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
				parentEl = parentEl.offsetParent;
			}
			parentEl = null;
			return totaloffset;		
		}
		catch(e){}
	};
	
	BarTab.ToolTip.ShowHide = function(obj, e)
	{
		try
		{
			BarTab.ToolTip.DropMenuObj.style.left = BarTab.ToolTip.DropMenuObj.style.top = "-500px";
			if (e.type=="mouseover")
				obj.visibility="visible";
		}
		catch(e){}
	};

	BarTab.ToolTip.IECompactTest = function()
	{
		try
		{
			return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
		}
		catch(e){}
	};

	BarTab.ToolTip.ClearBrowserEdge = function(obj, whichedge)
	{
		try
		{
			if (whichedge == "rightedge")
			{
				edgeoffsetx = 0;
				var windowedge = BarTab.ToolTip.IE && !window.opera? BarTab.ToolTip.IECompactTest().scrollLeft+BarTab.ToolTip.IECompactTest().clientWidth - 15 : window.pageXOffset+window.innerWidth - 15;
				BarTab.ToolTip.DropMenuObj.contentmeasure = BarTab.ToolTip.DropMenuObj.offsetWidth;
				if (windowedge-BarTab.ToolTip.DropMenuObj.x < BarTab.ToolTip.DropMenuObj.contentmeasure)
					edgeoffsetx = BarTab.ToolTip.DropMenuObj.contentmeasure - obj.offsetWidth;
					
				windowedge = null;	
				return edgeoffsetx;
			}
			else
			{
				edgeoffsety = 0;
				var topedge = BarTab.ToolTip.IE && !window.opera? BarTab.ToolTip.IECompactTest().scrollTop : window.pageYOffset;
				var windowedge = BarTab.ToolTip.IE && !window.opera? BarTab.ToolTip.IECompactTest().scrollTop + BarTab.ToolTip.IECompactTest().clientHeight - 15 : window.pageYOffset+window.innerHeight - 18;
				BarTab.ToolTip.DropMenuObj.contentmeasure = BarTab.ToolTip.DropMenuObj.offsetHeight;
				if (windowedge - BarTab.ToolTip.DropMenuObj.y < BarTab.ToolTip.DropMenuObj.contentmeasure) //move up?
					edgeoffsety = BarTab.ToolTip.DropMenuObj.contentmeasure + obj.offsetHeight + (BarTab.ToolTip.VerticalOffset*2);
					
				topedge = null;
				windowedge = null;
				return edgeoffsety
			}
		}
		catch(e){}
	};

	//main ballooon tooltip function
	BarTab.ToolTip.DisplayBallonToolTip = function(obj, e)
	{ 	
		try
		{
			if (window.event) 
				event.cancelBubble = true;			
			else if (e.stopPropagation) 
				e.stopPropagation();
				
			if (BarTab.ToolTip.DropMenuObj) //hide previous tooltip?
				BarTab.ToolTip.DropMenuObj.style.visibility = "hidden";
				
			BarTab.ToolTip.ClearHideMenu();
			BarTab.ToolTip.DropMenuObj = document.getElementById("divTabTabTooltip");
			BarTab.ToolTip.DropMenuObj.innerHTML = obj.getAttribute("tooltip")? obj.getAttribute("tooltip"): "";
			BarTab.ToolTip.ShowHide(BarTab.ToolTip.DropMenuObj.style, e);
			BarTab.ToolTip.DropMenuObj.x = BarTab.ToolTip.GetPositionOffset(obj, "left");
			//BarTab.ToolTip.DropMenuObj.y = BarTab.ToolTip.GetPositionOffset(obj, "left");
			BarTab.ToolTip.DropMenuObj.y = BarTab.ToolTip.GetPositionOffset(obj, "top") + BarTab.ToolTip.VerticalOffset;
			BarTab.ToolTip.DropMenuObj.style.left = BarTab.ToolTip.DropMenuObj.x - BarTab.ToolTip.ClearBrowserEdge(obj, "rightedge") + "px";
			BarTab.ToolTip.DropMenuObj.style.top=BarTab.ToolTip.DropMenuObj.y - BarTab.ToolTip.ClearBrowserEdge(obj, "bottomedge") + obj.offsetHeight + "px";
			if (BarTab.ToolTip.EnableArrowHead)
				BarTab.ToolTip.DisplayToolTipArrow();
		}
		catch(e){}
	};

	// Function to display optional arrow image associated with tooltip
	BarTab.ToolTip.DisplayToolTipArrow = function()
	{ 
		try
		{
			BarTab.ToolTip.Arrow = document.getElementById("arrowhead");
			BarTab.ToolTip.Arrow.src = (edgeoffsety != 0)? BarTab.ToolTip.ArrowHeadImg[0] : BarTab.ToolTip.ArrowHeadImg[1];
			var ieshadowwidth = (BarTab.ToolTip.DropMenuObj.filters && BarTab.ToolTip.DropMenuObj.filters[0])? BarTab.ToolTip.DropMenuObj.filters[0].Strength - 1 : 0;
			
			//modify "left" value depending on whether there's no room on right edge of browser to display it, respectively
			BarTab.ToolTip.Arrow.style.left = (edgeoffsetx != 0)? parseInt(BarTab.ToolTip.DropMenuObj.style.left) + BarTab.ToolTip.DropMenuObj.offsetWidth - BarTab.ToolTip.Arrow.offsetWidth - 10 + "px" : parseInt(BarTab.ToolTip.DropMenuObj.style.left) + 5 + "px";
			
			//modify "top" value depending on whether there's no room on right edge of browser to display it, respectively
			BarTab.ToolTip.Arrow.style.top = (edgeoffsety != 0)? parseInt(BarTab.ToolTip.DropMenuObj.style.top) + BarTab.ToolTip.DropMenuObj.offsetHeight - BarTab.ToolTip.Arrow.offsetHeight - ieshadowwidth+BarTab.ToolTip.ArrowHeadHeight + "px" : parseInt(BarTab.ToolTip.DropMenuObj.style.top) - BarTab.ToolTip.ArrowHeadHeight + "px";
			BarTab.ToolTip.Arrow.style.visibility = "visible";
			ieshadowwidth = null;
		}
		catch(e){}
	};

	BarTab.ToolTip.DelayHideMenu = function()
	{
		try
		{
			BarTab.ToolTip.DelayToHide = setTimeout("BarTab.ToolTip.DropMenuObj.style.visibility='hidden'; BarTab.ToolTip.DropMenuObj.style.left=0; if (BarTab.ToolTip.EnableArrowHead) BarTab.ToolTip.Arrow.style.visibility='hidden'; BarTab.ToolTip.DropMenuObj.innerHTML = '';", BarTab.ToolTip.DisappearDelay);
		}
		catch(e){}
	};

	BarTab.ToolTip.ClearHideMenu = function()
	{
		try
		{
			if (BarTab.ToolTip.DelayToHide)
				{clearTimeout(BarTab.ToolTip.DelayToHide);}
		}
		catch(e){}
	};	
}