/*
 * Copyright : (c) 2010 Webfish IT Services
 * Website   : http://www.webfish.nl
 * Email     : info@webfish.nl
 * -------------------------------------------------------------------------
 *   $Id: jquery.hint.js 11 2011-04-29 10:46:29Z caspar $
 * -------------------------------------------------------------------------
 */

(function($){

	$.fn.hint = function(options){

		var defaults = {
			hint:false
		};
		options = $.extend(defaults, options);

		return this.each(function(){
			var $new_input;
			var $input = $(this);
			var title  = (options.hint === false) ? $input.attr('title') : options.hint;

			if (title)
			{
				function inputFocus()
				{
					if ($new_input)
					{
						$input.show().focus();
						$new_input.hide();
					}
				}

				function inputBlur()
				{
					if ($input.val() === '')
					{
						if ($new_input)
						{
							$input.hide();
							$new_input.show();
						}
					}
				}

				$new_input = $('<input type="text" />')
					.attr('id', $input.attr('id')+'_text')
					.attr('title', $input.attr('title'))
					.val(title)
					.attr('className', $input.attr('className'))
					.focus(inputFocus)
					.insertBefore($input);

				$input.blur(inputBlur).blur();
			}
		});
	};

})(jQuery);
