/**
 * jQuery Placeholder plugin 0.1
 * by Sam Hastings
 *
 * This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
 *
 */

(function($) {

	$.fn.placeholder = function(params) {

		var params = $.fn.extend({ active: "#000000", inactive: "#000000", hide: true }, params);
		
		$(this).each(function() {
			
			var n = $(this);
			var label = $("label[for='" + n.attr("id") + "']");

			if(n.is(":text") && label.length) {

				var text = label.text();

				if(params.hide === true) {
					label.css("position", "absolute")
						 .css("left", "-10000px");
				}

				if(n.val().length === 0 || n.val() === text) {
					n.val(text).css("color", params.inactive);
				}

				n.bind({
					focus: function() {
						if(n.val() === text) {
							n.val("").css("color", params.active);
						}
					},
					blur: function() {
						if(n.val().length === 0) {
							n.val(text).css("color", params.inactive);
						}
					}
				});

				n.parents("form").bind("submit", function() {
					if(n.val() === text) {
						return false;
					}
				});

			}

		});

		return this;

	};

})(jQuery);
