/**
 * jQuery Placeholder plugin:
 * Swaps input field text with placeholder on blur/focus
 *
 * @version 1.0
 * @author Zach Waugh <zwaugh@gmail.com>
 * http://zachwaugh.com/projects/jquery-plugins/placeholder.html
 * 
 * Copyright (c) 2009 Zach Waugh
 * Licensed under the MIT License - http://www.opensource.org/licenses/mit-license.html
 * 
 */

(function($)
{
	$.fn.placeholder = function()
	{
		return this.each(function()
		{
			var $this = $(this);
			// Remove default text on focus
			$this.focus(function()
			{
			  if ($this.val() == $this.attr('placeholder'))
			  {
				if ($this.attr('prev_value'))
				{
					$this.val($this.attr('prev_value'));
					$this.attr('prev_value', '');
				}
				else
				{
					$this.val('');
				}

			  	$this.removeClass('placeholder').addClass('placeholder-input');
			  }
			});
			
			$this.blur(function()
			{
				if ($this.val() == '' || $this.hasClass('placeholder'))
				{
					$this.addClass('placeholder').removeClass('placeholder-input');
					$this.val($this.attr('placeholder'));
				}
			});
		});
	}
})(jQuery);
