/************************************************ 
 * Copyright © 2009 FL-2. All Rights Reserved.  *
 * Updated by: Matt Wiggins, 22-Jul-2009        *
 *                                              *
 * The tip is the king of tools.                *
 *                                              *
 * NOTE: Requires jQuery.                       *
 ************************************************
/                                              */
Tooltip = {
	/************************************************ 
	 * class members                                *
	 ************************************************
	/                                              */
	// internal stuff
	_ready:false,
	_divTooltip:null,
	
	/************************************************ 
	 * init:void                                    *
	 *                                              *
	 * NOTE: a call to this method is required and  *
	 * must be made after the document is ready.    *
	 ************************************************
	/                                              */
	init:function() {
		// if jQuery hasn't joined the party ...
		if(typeof($) == 'undefined')
		{
			throw("Error: jQuery is required for this page to function properly.");
			return;
		}
		
		// build the tooltip div
		Tooltip._divTooltip = document.createElement('div');
		Tooltip._divTooltip.id = 'fl2-tooltip'; // see this class in global.css
		Tooltip._divTooltip.style.display = 'none';
		document.body.appendChild(Tooltip._divTooltip);
		
		Tooltip._ready = true;
	},
	
	/************************************************ 
	 * _initMouseFollow:void                        *
	 ************************************************
	/                                              */
	_initMouseFollow:function() {
		$(document).mousemove(function(e) {
			Tooltip._divTooltip.style.top = (e.pageY - 227) + 'px';
			Tooltip._divTooltip.style.left = (e.pageX - 5) + 'px';
		});
	},	
	
	/************************************************ 
	 * _cancelMouseFollow:void                      *
	 ************************************************
	/                                              */
	_cancelMouseFollow:function() {
		$(document).unbind('mousemove');
	},
	
	/************************************************ 
	 * _actualHide:void                             *
	 ************************************************
	/                                              */
	_actualHide:function() {
		Tooltip._cancelMouseFollow();
		$(Tooltip._divTooltip).stop(true, true);
		$(Tooltip._divTooltip).css('display', 'none');
	},	
	
	/************************************************ 
	 * setContent:void                              *
	 *                                              *
	 * content:String - HTML content                *
	 ************************************************
	/                                              */
	setContent:function(content) {
		if(!Tooltip._ready) return;
		Tooltip._divTooltip.innerHTML = content;
	},
	
	/************************************************ 
	 * setPosition:void                             *
	 *                                              *
	 * x:Number - x position                        *
	 * y:Number - y position                        *
	 ************************************************
	/                                              */
	setPosition:function(x, y) {
		if(!Tooltip._ready) return;
		Tooltip._divTooltip.style.top = (y - 227) + 'px';
		Tooltip._divTooltip.style.left = (x - 5) + 'px';
	},
	
	/************************************************ 
	 * show:void                                    *
	 *                                              *
	 * follow:Boolean - specifies whether the       *
	 * tooltip should follow the mouse or not       *
	 ************************************************
	/                                              */
	show:function(follow) {
		if(!Tooltip._ready) return;
		if(follow) Tooltip._initMouseFollow(); 
		$(Tooltip._divTooltip).fadeIn('slow');
	},
	
	/************************************************ 
	 * hide:void                                    *
	 *                                              *
	 * delay:Number - optional delay                *
	 ************************************************
	/                                              */
	hide:function(delay) {
		if(!Tooltip._ready) return;
		if(typeof(delay) == 'undefined') delay = 0;
		setTimeout(Tooltip._actualHide, delay);
	}
}