// EZPZ Hint v1.1.1; Copyright (c) 2009 Mike Enriquez, http://theezpzway.com; Released under the MIT License
(function($){
	$.fn.ezpz_hint = function(options){
		var defaults = {
			hintClass: 'ezpz-hint',
			hintName: 'ezpz_hint_dummy_input'
		};
		var settings = $.extend(defaults, options);
		
		return this.each(function(){
			var hint;
			var dummy_input;
			var input = $(this);
			value = $(this).attr('title');				
			// grab the input's title attribute
			value = $(this).attr('title');
			// create a dummy input and place it before the input
			$('<input type="hidden" name="temp" value="" />').insertBefore($(this));
			
			// set the dummy input's attributes
			hint = $(this).prev('input:first');
			hint.attr('name', settings.hintName);
			hint.attr('id', "temp_"+$(this).attr("id"));
			hint.addClass("temp");
			hint.val(value);
			
			$(input).focus(function(){
				//temp_hint = $(this).prev('input:first');
				//alert($(this).attr("id"));
				temp_hint = $("#temp_"+$(this).attr("id"));
				//alert($(temp_hint).attr("id"));
				input = $(this);
				old_value = $(this).val();
				value = $(temp_hint).val();
				if(old_value == value)
				{
					$(input).val('');
				}
				
				$(this).blur(function(){
						if($(input).val()=="" || $(input).val()== value)
						{
							$(input).val(value);
						}
				});
			});
			
			// swap if there is a default value
			if ($(this).val() == ''){
				$(this).val(value);
			};
			
			// remove the dummy inputs so that they don't get submitted
			$('form').submit(function(){
				$('.' + settings.hintName).remove();
			});
		});
		
	};
})(jQuery);