/**
 * Por Design Placeholder
 *
 * Copyright (c) 2010 Por Design (pordesign.eu)
 * 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.placeholder = function(options)
	{
		options = $.extend
		({
		}, options);
		
		$(this).each( function()
		{
			if ($(this).attr('name') != '' && $(this).attr('name') in options)
			{
				placeholder = options[$(this).attr('name')];
				$(this).data('placeholder', placeholder);
				
				if ($(this).val() == '')
				{
					$(this).val(placeholder);
				}
			} else
			{
				$(this).data('placeholder', '');
			}
		});

		$(this).focus( function()
		{
			if ($(this).val() == $(this).data('placeholder'))
			{
				$(this).val('');
			}
		});
			
		$(this).blur( function()
		{
			if ($(this).val() == '')
			{
				$(this).val($(this).data('placeholder'));
			}
		});

		$(this).parents('form').submit( function()
		{
			$(this).find('input, textarea').each( function()
			{
				if ($(this).data('placeholder') != '')
				{
					if ($(this).val() == $(this).data('placeholder'))
					{
						$(this).val('');
					}
				}
				
				$(this).blur();
			});
		});

		return this;
	}
})(jQuery);

