// Pop-up tool tip on mouseover

$( 'head' ).append ( '<link rel="stylesheet" type="text/css" href="/articles/miscellany/css/tips.css" media="screen" />' );

var tipX = 0;
var tipY = 20;
var tip_cursor = "pointer";
var tip_done = false;
var tip_text;

$( document ).ready ( function ()
	{
		$( ".tips" ).each ( function ()
			{
				tip_text = $( this ).attr ( "title" );
				if ( tip_text ) $( this ).removeAttr ( "title" ).attr ( "tip_title", tip_text );
			}
		);
	}
);

$( document ).ready ( function ()
	{
		$( ".tips" ).mouseover ( function ()
			{
				if ( !tip_done ) {
					$( this ).css ( "cursor", tip_cursor );
					var offset = $( this ).attr ( "rel" ) == "left" ? 0 : 420 ;
					$( document.body ).append ( "<div id='tip'>" + $( this ).attr ( "tip_title" ) + "</div>" );
					$( "#tip" ).show ();
					tip_done = true;
				}
				$( this ).mousemove ( function (e)
					{
						$( "#tip" ).css (
							{
								top: ( e.pageY + tipY ) + "px",
								left: ( e.pageX + tipX - offset ) + "px"
							}
						);
					}
				);
			}
		).mouseout ( function ()
			{
				$( "#tip" ).hide ().remove ();
				tip_done = false;
			}
		);
	}
);
