/*
 * jQuery Input Hint Overlay plugin v1.1.7, 2010-04-05
 * Only tested with jQuery 1.4.1 (early versions - YMMV)
 * 
 *   http://jdeerhake.com/inputHintOverlay.php
 *   http://plugins.jquery.com/project/inputHintOverlay
 *
 *
 * Copyright (c) 2010 John Deerhake
 *
 * Dual licensed under the MIT and GPL licenses:
 *   http://www.opensource.org/licenses/mit-license.php
 *   http://www.gnu.org/licenses/gpl.html
 */
jQuery.fn.inputHintOverlay = function (topNudge, leftNudge) {
	topNudge = typeof(topNudge) != 'undefined' ? topNudge : 0;
	leftNudge = typeof(leftNudge) != 'undefined' ? leftNudge : 0;
	var suffix = 'jqiho';
	return this.each(function (){
		var curParent = $(this);
		var textAreas = $(this).find("textarea");
		var pass = $(this).find("input[type=password]")
		$(this).find("input[type=text]").add(textAreas).add(pass).each(function() {
			var relHint = $(this).attr('title');
			var curValue = $(this).attr('value');
			var inp = $(this);
			var safeHint;
			if(relHint) {
				safeHint = relHint.replace(/[^a-zA-Z0-9]/g, 'O');
				$(this).wrap("<div style='position:relative' id='wrap" + safeHint + suffix + "' />");
				var newPos = $(this).position();
				newZ = $(this).css('z-index');
				if(newZ == "auto") newZ = "2000";
				else newZ = newZ + 20;
				var newCSS = {
					'position' : 'absolute',
					'z-index' : newZ,
					'left' : newPos['left'] + leftNudge,
					'top': newPos['top'] + topNudge,
					'cursor' : 'text'
				};
				newDiv = $(document.createElement('label'))
					.appendTo($("div#wrap" + safeHint + suffix))
					.attr('for', $(this).attr('id'))
					.attr('id', safeHint + suffix)
					.addClass('inputHintOverlay')
					.html(relHint)
					.css(newCSS)
					.click(function() {
						$(this).toggle(false);
						inp.trigger("focus");
					});
			}
			if(curValue) {
				$('#' + safeHint + suffix).toggle(false);
			}
			$(this).focus(function() {
				$('#' + safeHint + suffix).toggle(false);
			});
			$(this).blur(function() {
				if ($(this).attr('value') == "") { $('#' + safeHint + suffix).toggle(true); }
			});
		});
	});
}

