///////////////////////////////////////////////////////
///////////////////////////////////////////////////////
//
//	WIDGET_TOOLTIP.JS v1.0A created June 27, 2006
//	by Matt Garvin, mgarvin@algorithmics.com
//		- Feel free to use this widget in any of your porjects, commercial
//		  or otherwise.  You can use code as is, or modify to see your needs,
//		  all that I ask is you give me some credit in your source code by
//		  including my name and email address.
//		- This widget goes hand in hand with widget_tooltip.css
//		  which is used to style the popup.
//		- It also requires a table like this -> <table id="tooltip"> <-
//		  somewhere in the page that will contain a tooltip.
//		- here is the code to launch it:
//
//			<a href="javascript: void(0);" onmouseover="tooltip('This is a standard tooltip!')" onmouseout="tooltip('')">Show tooltip</a>
//
///////////////////////////////////////////////////////
///////////////////////////////////////////////////////


	// Tooltip Configuration values
	var TT_offset_X			=	10;			// offset from mouse pointer on X axis
	var TT_offset_Y			=	4;			// offset from mouse pointer on Y axis
	var TT_locked			= 	false;		// should tip stay put or move with mouse?
	var TT_CSS_Array		= 	new Array() // an array for different tooltip styles below.  Attributes are separated by ^

		//						fnt clr ^fnt sz 	^backgr 					^bdr clr^padding 	^font family
		//						-------  ------  	 ------- 					 ------- -------  	 -----------
		TT_CSS_Array[0]		=	'black  ^11px		^#ff9   					^#000   ^4px     	^Tahoma, Geneva, Arial, Helvetica, sans-serif'
		TT_CSS_Array[1]		=	'#000   ^xx-small	^#fee   					^#000   ^2 10 2 10  ^Georgia, "Times New Roman", Times, serif' 
		TT_CSS_Array[2]		=	'#FFFF00^100%		^url("tooltip_bg_fancy.jpg")^#000   ^3px     	^"Comic Sans MS", Jokerman, fantasy'  
	
	// Tooltip needed global variables
 	var mouseX, mouseY;					// co-ordinates of mouse pointer
	var TT_mousemssg	=	'';			// The message to display


///////////////////////////////////////////////////////


	if(window.Event && document.captureEvents)		// attach mouse movements to getMouseXY() function
		document.captureEvents(Event.MOUSEMOVE);	// based on code from Stephen Chalmers at
													// http://www.thescripts.com/forum/thread157393.html
	document.onmousemove = getMouseXY;	


///////////////////////////////////////////////////////

	function getMouseXY(e)
	{
		if(!e)
			var e = window.event||window.Event;
		
		if('undefined'!=typeof e.pageX && !TT_locked)
			{
			 mouseX = e.pageX;
			 mouseY = e.pageY;
			}
		else if(!TT_locked)
			{
			 mouseX = e.clientX + document.body.scrollLeft;
			 mouseY = e.clientY + document.body.scrollTop;
			}
		if(TT_mousemssg!='')				// If tooltip should be visible (a link is being hovered over)
			 tooltip(TT_mousemssg)		// call the tooltip() function
	}	

///////////////////////////////////////////////////////

	// Make Trim function for whitespace (this code was copied from Jim Ley's "Javascript FAQ" at http://www.jibbering.com/faq/#FAQ4_16)
	String.prototype.LTrim =		new Function("return this.replace(/^\\s+/,'')")
  	String.prototype.RTrim =		new Function("return this.replace(/\\s+$/,'')")
  	String.prototype.Trim  =	    new Function("return this.replace(/^\\s+|\\s+$/g,'')")
								    
///////////////////////////////////////////////////////
								    
   	function set_Styles(TT_CSS_Index) 
   {
   	var split_CSS = TT_CSS_Array[TT_CSS_Index].split('^')
	document.getElementById('tooltip_mssg').style.color 		= split_CSS[0].Trim()
	document.getElementById('tooltip_mssg').style.fontSize	 	= split_CSS[1].Trim()	
	document.getElementById('tooltip_mssg').style.background 	= split_CSS[2].Trim()	
	document.getElementById('tooltip_mssg').style.borderColor 	= split_CSS[3].Trim()	
	document.getElementById('tooltip_mssg').style.padding 		= split_CSS[4].Trim()
	document.getElementById('tooltip_mssg').style.fontFamily 	= split_CSS[5].Trim()
	return true;
   }	

////////////////////////////////////////////////////////////////////////////////////
// FUNCTION tooltip(bool,mssg) is
// the meat of this widget.  It accepts two values:
// "bool" is a boolean for on or off, 1 and 0 respectively
// "mssg" is a string which is the content of the tooltip
////////////////////////////////////////////////////////////////////////////////////

	 function tooltip(mssg,locked,CSS)
	{
	 if(TT_mousemssg == '')		// function called for first time, set CSS
	 	{
		 if(locked==null || locked=='undefined')
		 	locked = false;
		 if(CSS==null || CSS=='undefined')
		 	CSS = 0;
		 set_Styles(CSS)		
		 TT_locked = locked
		}	 	
		
	 if(mssg=='') 
		{
		 // and empty mssg means "Turn tip off!"	
		 window.status = '';
		 document.getElementById('tooltip').style.display = 'none'
		 TT_mousemssg = '';		// set global TT_mousemssg to nothing so it will keep displaying...
		 TT_locked = false;
		}
	 else
		{
		 // turn the tip on!	
		 document.getElementById('tooltip').style.left = mouseX + TT_offset_X
		 document.getElementById('tooltip').style.top  = mouseY + TT_offset_Y
		 document.getElementById('tooltip_mssg').innerHTML = mssg

		 var status_mssg = mssg.replace(/(<([^>]+)>)/ig,""); 	// strip HTML from the message and display in status area
		 	 window.status = status_mssg

		 document.getElementById('tooltip').style.display = 'inline'
		 TT_mousemssg = mssg	// set global TT_mousemssg to the mssg so it will keep displaying...
		}
	 return true;
	}