/************************************************************************************************************
	(C) www.dhtmlgoodies.com, October 2005
	
	This is a script from www.dhtmlgoodies.com. You will find this and a lot of other scripts at our website.	
	
	Updated:	
		March, 11th, 2006 - Fixed positioning of tooltip when displayed near the right edge of the browser.
		April, 6th 2006, Using iframe in IE in order to make the tooltip cover select boxes.
		
	Terms of use:
	You are free to use this script as long as the copyright message is kept intact. However, you may not
	redistribute, sell or repost it without our permission.
	
	Thank you!
	
	www.dhtmlgoodies.com
	Alf Magne Kalleland
	
************************************************************************************************************/	
	var sg_tooltip = false;
	var sg_tooltipShadow = false;
	var sg_shadowSize = 4;
	var sg_tooltipMaxWidth = 200;
	var sg_tooltipMinWidth = 100;
	var sg_iframe = false;
	var tooltip_is_msie = (navigator.userAgent.indexOf('MSIE')>=0 && navigator.userAgent.indexOf('opera')==-1 && document.all)?true:false;
	function showTooltip(e,tooltipTxt)
	{
		//alert('dsfsd');
		var bodyWidth = Math.max(document.body.clientWidth,document.documentElement.clientWidth) - 20;
	
		if(!sg_tooltip){
			sg_tooltip = document.createElement('DIV');
			sg_tooltip.id = 'sg_tooltip';
			sg_tooltipShadow = document.createElement('DIV');
			sg_tooltipShadow.id = 'sg_tooltipShadow';
			
			document.body.appendChild(sg_tooltip);
			document.body.appendChild(sg_tooltipShadow);	
			
			if(tooltip_is_msie){
				sg_iframe = document.createElement('IFRAME');
				sg_iframe.frameborder='5';
				sg_iframe.style.backgroundColor='#FFFFFF';
				sg_iframe.src = '#'; 	
				sg_iframe.style.zIndex = 100;
				sg_iframe.style.position = 'absolute';
				document.body.appendChild(sg_iframe);
			}
			
		}
		
		sg_tooltip.style.display='block';
		sg_tooltipShadow.style.display='block';
		if(tooltip_is_msie)sg_iframe.style.display='block';
		
		var st = Math.max(document.body.scrollTop,document.documentElement.scrollTop);
		
		var leftPos = e.clientX + 10;
		
		sg_tooltip.style.width = null;	// Reset style width if it's set 
		sg_tooltip.innerHTML = tooltipTxt;
		sg_tooltip.style.left = leftPos + 'px';
		sg_tooltip.style.top = e.clientY + 10 + st + 'px';

		
		sg_tooltipShadow.style.left =  leftPos + sg_shadowSize + 'px';
		sg_tooltipShadow.style.top = e.clientY + 10 + st + sg_shadowSize + 'px';
		
		if(sg_tooltip.offsetWidth>sg_tooltipMaxWidth){	/* Exceeding max width of tooltip ? */
			sg_tooltip.style.width = sg_tooltipMaxWidth + 'px';
		}
		
		var tooltipWidth = sg_tooltip.offsetWidth;		
		if(tooltipWidth<sg_tooltipMinWidth)tooltipWidth = sg_tooltipMinWidth;
		
		
		sg_tooltip.style.width = tooltipWidth + 'px';
		sg_tooltipShadow.style.width = sg_tooltip.offsetWidth + 'px';
		sg_tooltipShadow.style.height = sg_tooltip.offsetHeight + 'px';		
		
		if((leftPos + tooltipWidth)>bodyWidth){
			sg_tooltip.style.left = (sg_tooltipShadow.style.left.replace('px','') - ((leftPos + tooltipWidth)-bodyWidth)) + 'px';
			sg_tooltipShadow.style.left = (sg_tooltipShadow.style.left.replace('px','') - ((leftPos + tooltipWidth)-bodyWidth) + sg_shadowSize) + 'px';
		}
		
		if(tooltip_is_msie){
			sg_iframe.style.left = sg_tooltip.style.left;
			sg_iframe.style.top = sg_tooltip.style.top;
			sg_iframe.style.width = sg_tooltip.offsetWidth + 'px';
			sg_iframe.style.height = sg_tooltip.offsetHeight + 'px';
		
		}
				
	}
	
	function hideTooltip()
	{
		sg_tooltip.style.display='none';
		sg_tooltipShadow.style.display='none';		
		if(tooltip_is_msie)sg_iframe.style.display='none';		
	}