/*
 * jQuery textBoxInstructions plugin
 * Version 1.0  (2008-01-11)
 * @requires jQuery v1.1.3 or above
 *
 * Copyright (c) 2008 Softwyre, Inc. (www.softwyre.com)
 * 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.textBoxInstructions = function(text, instructionsClass)
{
    return this.each(function(){
		if (!instructionsClass) instructionsClass = 'instructions';
		if (this.type == 'password')
		{
			//replace the password input with a text input
			$(this)
				.hide()
				.after('<input type="text" class="surrogate ' + $(this).attr('class') + '" />')
				.blur(function(){
					if (this.value=='')
					{
						$(this).hide();
						$('.surrogate', this.parentNode).show();
					}	
				})
				;
			$('.surrogate', this.parentNode)
				.addClass(instructionsClass)
				.val(text)
				.focus(function(){
					$(this).hide();
					
					$(':password', this.parentNode)
						.show()
						.focus()
						;
				})
				;
		}
		else
		{
	        $(this)
				.addClass(instructionsClass)
				.focus(function(){
					if ($(this).hasClass(instructionsClass))
					{
						this.value='';
						$(this).removeClass(instructionsClass);
					}
				})
				.blur(function(){
					if(this.value=='')
					{
						this.value=text;
						$(this).addClass(instructionsClass);
					}
				})
				.each(function(){this.value=text;})
				;
		}
	});
}
})(jQuery);