/* Form Label plugin for jQuery
- http://www.doubleclique.com
- 2009 Shane Garelja

Minimum CSS:
label {
	cursor:text;
	position:absolute;
	z-index:2;
}

Ideal markup example:
<div class="inputLayout">
	<span class="fieldHolder ">
		<label for="contactFieldName">Name*</label>
		<input name="Name" id="Name" type="text" value="" autocomplete="off" />
	</span>
</div>

You should also add a noscript option to top of page - e.g.:
<noscript>
	<style>
		label {
			position:static;
		}
	</style>
</noscript>
 */

;(function($){

	$.fn.smartlabels = function(options) {

		var settings = $.extend(
			{
				inputSelector : "input[type='text'], input[type='password'], textarea",
				fadeTo : '0.6',
				keydownCallback : function(el) {
					$(el).closest('.fieldHolder').removeClass('error');
				}
			},
			options
		);

		return this.each(
			function(index, el) {
				var inputSelector = $(el).find(settings.inputSelector);
				var fadeLabel = function(el) {
					$(el).find('label').fadeTo(200, settings.fadeTo);
				}
				$(el).find('label').click( function() {
						fadeLabel(el);
						inputSelector.focus();
					}
				);
				inputSelector.bind("click focus", function() { fadeLabel(el); });
				inputSelector.blur(
					function() {
						if ($.trim($(this).val()).length == 0) {
							$(el).find('label').css({'opacity':'1.0'}).show();
						} else {
							$(el).find('label').hide();
						}
					}
				);
				inputSelector.keydown(
					function(e) {
						if (e.which == 32 ||
							(48 <= e.which && e.which <= 57) ||
							(65 <= e.which && e.which <= 90) ||
							(97 <= e.which && e.which <= 122)) {
							$(el).find('label').hide();
							settings.keydownCallback(el);
						}
					}
				);
			}
		);
	};

})(jQuery);