/*
 * jQuery Labelise Plugin v1.0
 * 
 * Copyright (c) 2008 Robert O'Rourke (http://www.sanchothefat.com/)
 * 
 * Dual licensed under the MIT and GPL licenses:
 *   http://www.opensource.org/licenses/mit-license.php
 *   http://www.gnu.org/licenses/gpl.html
 */
;(function($) {
	$.fn.labelise = function(){
		$(this).each(function(){
			var $label = $(this);
			var $input = $("#" + $label.attr("for"));
			$label.addClass("hidden");
			var labeltext = $label.text();
			if ( $input.attr("type") == "password" )
				labeltext = "Password";
			$input.focus(function(){
				if ( $input.val() == labeltext ) {
					$(this).removeClass("islabel").val("");
				}}).blur(function(){
				if ( $input.val() == '' || $input.val() == labeltext ) {
					$(this).addClass("islabel").val(labeltext);
				}})
				.blur()
				.parents("form")
				.submit(function(){
					if ( $input.val() == '' || $input.val() == labeltext ) {
						$input.focus();
						return false;
					}
				});
		});
	};
})(jQuery);