(function($) {
  $.hint = {
    defaults: {
      hint: '',
      inlineClass: "inline-hint",
      blur: true
    },
    options: {}
  };
  $.fn.extend({
    hint: function(options) {
      $.hint.options = $.extend($.hint.defaults, options);
      var $this = $(this);
      this.each(function () {
        var $input = $(this);
        $(this.form).bind('submit', {input: this}, function(event) { $.fn.hint.reset(event.data.input); });
        $.fn.hint.addHint(this);
        $input.addClass('inline-hint');
        $input.bind('change', {input: this}, function(event) { $.fn.hint.addHint(event.data.input); });
        $input.bind('focus', {input: this}, function(event) { $.fn.hint.removeHint(event.data.input); });
        if (options.blur == null || options.blur == true) {
          $input.bind('blur', {input: this}, function(event) { $.fn.hint.addHint(event.data.input); });
        }
      })      
    }
  });
  $.fn.hint.addHint = function(input) {
    if (input.value == '' || input.value == $.hint.options.hint) {
      $(input).addClass('show-hint');
      input.value = $.hint.options.hint;
    }
  };
  $.fn.hint.removeHint = function(input) {
    $(input).removeClass('show-hint');
    if (input.value == $.hint.options.hint) {
      input.value = '';
    }
  };
  $.fn.hint.reset = function(input) {
    if (input.value == $.hint.options.hint) {
      input.value = '';
    }
  }
})(jQuery);
