/*
 * jQuery Input Hint Overlay plugin v1.1.3, 2010-03-10
 * 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
 */
;(function($) {
jQuery.fn.inputHintOverlay = function (topNudge, leftNudge) {
	topNudge = typeof(topNudge) != 'undefined' ? topNudge : 0;
	leftNudge = typeof(leftNudge) != 'undefined' ? leftNudge : 0;
	var suffix = '-ssjq';
	return this.each(function (){
		var curParent = $(this);
		$(this).add("input[type=password]").each(function() {
			var relHint = $(this).attr('title');
			var curValue = $(this).attr('value');
			//alert(relHint);alert(curValue);
			var safeHint;
			if(relHint) {
				safeHint = relHint.replace(/[^a-zA-Z0-9]/g, '');
				$(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',
					'float' : 'left',
					'clear' : 'both',
					'z-index' : newZ,
					'left' : newPos['left'] + leftNudge,
					'top': newPos['top'] + topNudge
				};
				newDiv = $(document.createElement('label'))
					.appendTo($("div#wrap" + safeHint + suffix))
					.attr('for', $(this).attr('id'))
					.attr('id', safeHint + suffix)
					.addClass('inputHintOverlay')
					.html(relHint)
					.css(newCSS);
			}
			if(curValue) {
				$('#' + safeHint + suffix).toggle(false);
			}
			$(this).focus(function() {
				$('#' + safeHint + suffix).toggle(false);
			});
			$(this).blur(function() {
				if ($(this).attr('value') == "") { $('#' + safeHint + suffix).toggle(true); }
			});
			
			/*if ($(this).attr('title')=='Email') {
				$(this).keyup(function() {
					//alert('pass: '+$(this).attr('title'));
					$(curParent).find("input[type=password]").each(function() {
						
						var curValue2 = $(this).attr('value');
						//alert('pass: '+curValue2);
						if(curValue2) {
							var relHint2 = $(this).attr('title');
							alert('hint: '+relHint2);
							var safeHint2 = relHint2.replace(/[^a-zA-Z0-9]/g, '');
							$('#' + safeHint2 + suffix).toggle(false);
						}
					});
				});
			}*/
		});
	});
}
})(jQuery);

