/*
 * jQuery plugin to toggle the value of an input field or textarea if focus() 
 *
 * (C) 2009, Fusion Ltd
 *
 */

(function ($) {
	 $.fn.toggleInput = function()
	 {
		return this.each(function () 
		{
			var $self = $(this);
			if ($self.is(":input") || $self.is(":textarea")) 
			{
				$self.data('orgVal', $self.val());
				$self.focus(function()
				{
					if($self.hasClass('labeled'))
					{
						$self.data('labeled', true);
						$self.removeClass('labeled')
					}
					if( $self.val() == $self.data('orgVal') )
						$self.val('');
				})
				$self.blur(function()
				{
					if( $self.val() == '' )
					{
						$self.val($self.data('orgVal'));
						if($self.data('labeled') == true)
							$self.addClass('labeled')
					}	
				})
			}
		});
	 }
})(jQuery);
