function createTooltip(tooltip) {

	var currentTip;

	$(tooltip).hover(function(e) {

		var item = $(this);
		currentTip = item.find("span").siblings("div.tooltip").clone().appendTo("body");

		setTimeout(function() {

			if (currentTip != null) {

				$(this).trigger("mousemove");

				var s = item.find("span");
				item.t = s.attr("title");
				s.attr("title", "");
				if ($.browser.msie)
					currentTip.show();
				else
					currentTip.fadeIn(200);
			}
		}, 300);
	},
		function() {

			if (currentTip != null) {

				$(this).find("span").attr("title", this.t);
				if ($.browser.msie)
					currentTip.remove();
				else
					currentTip.fadeOut(200, function() { $(this).remove() });
			}

		}).mousemove(function(e) {
			if (currentTip != null) {
				if ($.browser.msie && $.browser.version == 6.0) {
					currentTip.css({
						bottom: $(window).scrollTop() + $(window).height() - e.pageY + 5,
						left: e.pageX - 75
					});
				}
				else {
					currentTip.css({
						bottom: $(window).height() - e.pageY + 5,
						left: e.pageX - 75
					});
				}
			}
		});
}

function initTooltip() {

	$(".tooltip-item:has(span[title])").each(function() {
		createTooltip(this);
	});
}

function initFormTooltip() {
	$(".form-field input:text[title], .form-field textarea[title]").each(function() {

		var parent = $(this).closest(".form-field");

		var title = parent.find("label").text().replace(":", "");
		var text = $(this).attr("title");

		var t = $('<div style="display: none;" class="tooltip"><div class="tooltip-content"></div><div class="tooltip-bottom"/></div><span></span>');
		var c = t.find(".tooltip-content");
		c.append('<h4>' + title + '</h4><p>' + text + '</p>');

		$(this).removeAttr("title");
		parent.append(t);

		createTooltip(parent);
	});
}
