/**
 * jQuery UI Focus Tooltip 1.0
 *
 * @author Gabriel Lemonde-Labrecque
 * @requires jquery.ui.core.js
 * @requires jquery.ui.widget.js
 * @copyright 2010, SchoolSuccess inc.
 * @version 1.0
 */
(function($) {
	$.widget("ui.focustooltip", {
		options: {
			left: null,
			top: null,
			text: 'write here',
			cssclass: 'focus-tooltip'
		},
		_create: function() {
			var self = this;
			
			var $tooltip = $('.' + this.options.cssclass);
			
			if ($tooltip.length == 0) {
				$tooltip = $('<div class="' + this.options.cssclass + '"></div>');
				$('body').append($tooltip);
				$tooltip.hide();
			}
			
			if (this.options.left === null)
				this.options.left = this.element.offset().left;
			
			if (this.getTop() === null)
				this.options.top = function() { self.element.offset().top + self.element.outerHeight(); };
			
			this.element.focusin(function() {
				$tooltip.show().css({ 'position': 'absolute', 'left': self.options.left, 'top': self.getTop() }).html(self.options.text);
			}).focusout(function() {
				$tooltip.hide();
			}).keydown(function() {
				$tooltip.hide();
			});
		},
		getTop: function() {
			var self = this;
			
			if (typeof self.options.top == 'function')
				return self.options.top();
			
			return self.options.top;
		}
	});
})(jQuery);

