/**
* @author Remy Sharp
* @url http://remysharp.com/2007/01/25/jquery-tutorial-text-box-hints/
*/

(function ($) {

$.fn.hint = function (options) {
	if (!options) options = {};
    if (!options.blurClass) options.blurClass = 'blur';
    if (!options.clearFields) options.clearFields = true;

    return this.each(function () {
        var $input = $(this),
            title = $input.attr('title'),
            $form = $(this.form),
            $win = $(window);

        function remove() {
        	if ($input.val() === title && $input.hasClass(options.blurClass)) {
                $input.val('').removeClass(options.blurClass);
            }
        }

        // only apply logic if the element has the attribute
        if (title) {
            // on blur, set value to title attr if text is blank
            $input.blur(function () {
                if ($input.val() === '') {
                    $input.val(title).addClass(options.blurClass);
                }
            }).focus(remove).blur(); // now change all inputs to title

            // clear the pre-defined text when form is submitted
            if (options.clearFields)
            {
            	// if we have 5 fields in the form, then we bind a handler 5 times.
            	// need to do smth with that
            	$form.submit(remove);
            }
            $win.unload(remove); // handles Firefox's autocomplete
        }
    });
};

})(jQuery);