/*
 * placeholder
 * @requires jQuery v1.3 or later
 *
 * Creates a placeholder hint in text inputs
 *
 * Licensed under the MIT:
 * http://www.opensource.org/licenses/mit-license.php
 *
 * Copyright (c) 2009, Matt Wigham - Indie Labs, LLC
 */

(function($) {

	$.fn.placeholder = function(text) {
				
		return this.each(function() {
			
			var $this = $(this);
			
			$this.parent('form').submit(function() {
				removePlaceHolder($this, text);
			});
			
			$this.focus(function() { 
				removePlaceHolder($this, text);
			});

			$this.blur(function() {
				addPlaceHolder($this, text);
			});			
			
			addPlaceHolder($this, text);
			
		});

	};
	
	$.fn.placeholder.defaults = {
		className: 'placeholder'		
	};
	
	function addPlaceHolder(elm, text) {
		if(elm.val() == '') {
			elm.addClass($.fn.placeholder.defaults.className);
			elm.val(text);
		}
	};
	
	function removePlaceHolder(elm, text) {
		if(elm.val() == text) {
			elm.removeClass($.fn.placeholder.defaults.className);
			elm.val('');
		}
	};

})(jQuery);

$(document).ready(function() {
	
	$('input[placeholder]').each(function() {	
		var $this = $(this);
			$this.placeholder($this.attr('placeholder'));				
	});	

});
