;(function($) {

$.rad = $.rad || {};

$.rad.placeholders = {
	defaults: {
	},
	
	hasNativeSupport: function() {
		return 'placeholder' in document.createElement('input');
	}
};

$.fn.placeholders = function(options) {
	var opts = $.extend({}, $.rad.placeholders.defaults, options),
		ns = $.rad.placeholders.hasNativeSupport();
	
	return this.each(function() {
		var $this = $(this),
			inputType = $this.attr("type").toLowerCase(),
			ph;
		
		// only makes sense for text inputs and textareas
		if (!(inputType === "text" ||
			  inputType === "password" ||
			  inputType === "textarea"))
			return;
		
		ph = $this.attr("placeholder");
		
		if (!ph || ph === '')
			return;
		
		if (this.value == '') {
			if (!ns) {
				this.value = ph;
				if (inputType === "password")
					this.type = "text";
			}
			$this.addClass("ph");
		}
		
		$this.focus(function() {
			if (this.value == ph) {
				if (!ns) {
					this.value = '';
					if (inputType === "password")
						this.type = "password";
				}
			}
			$this.removeClass("ph");
		 }).blur(function() {
			if (this.value == '') {
				if (!ns) {
					this.value = ph;
					if (inputType === "password")
						this.type = "text";
				}
				$this.addClass("ph");
			}
		}).parents("form").submit(function() {
			if ($this.val() == ph)
				$this.val('');
		});
	});
};

})(jQuery);

