/**
 * jQuery Tooltip plugin 1.1
 *
 * Copyright (c) 2008 Ruslan V. Us
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
jQuery.extend
({
	bindTooltip: function (id)
	{
		if (!id) id = "___tooltip";

		var tElement = jQuery ("#" + id);
		if (tElement.size () == 0)
			tElement = jQuery ("<div></div>")
				.attr ("id", id)
				.css ("position", "absolute")
				.hide ()
				.prependTo (document.body);

		jQuery ("[tooltip='" + id + "']")
			.bind ("mouseenter", function ()
			{
				var element = jQuery (this);
				if (element.attr ("disabled") || !element.attr ("caption")) return;

				var tooltip = jQuery ("#" + element.attr ("tooltip"));
				tooltip.empty ();
				tooltip.append (element.attr ("caption"));
				tooltip.show ();
			})
			.bind ("mouseleave", function ()
			{
				jQuery ("#" + jQuery (this).attr ("tooltip")).hide ();
			})
			.bind ("mousemove", function (event)
			{
				var element = jQuery (this);
				if (!element.attr ("disabled"))
					jQuery ("#" + element.attr ("tooltip")).css
					({
						left: event.pageX + 16,
						top: event.pageY + 16
					});
			});

		return tElement;
	}
});

