if (!jQuery.addPlugin){
  /**
    Utility to add a plugin to jQuery, using the way recommended by jQuery:
    - One method to access all functionality in the plugin.
    - The first argument of the method is the actual method name to be executed.
    - The rest of the arguments are passed to the actual method.
    - If the first argument is an object instead of a method name (or if no
      arguments are given at all), the init() method of the plugin is called
      and the given object is used as a set of options.

    @param name The name of the plugin.
    @param methods The public methods that the plugin offers.

    @author Jan Willem Nienhuis
  */
  jQuery.addPlugin = function (name, methods) {
    jQuery.fn[name] = function(method) {
      // Method calling logic
      if ( methods[method] ) {
        return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 ));
      } else if ( typeof method === 'object' || ! method ) {
        return methods.init.apply( this, arguments );
      } else {
        jQuery.error( 'Method ' +  method + ' does not exist on jQuery.' + name);
      }
    };
  };
}

/*
  Input Hint plugin.

  @author Jan Willem Nienhuis
*/
(function( $ ){

  var pluginName = 'inputhint';
  var defaultSettings = {
    inputShowingHintClass: 'value-is-hint'
  };
  var methods = {
    init: function( options ) {
      return this.each(function (){
        var element = $(this);

        // Handle the settings.
        var settings = $.extend( {}, defaultSettings );
        if ( options ) { settings = $.extend( settings, options ); }
        element.data(pluginName, settings);

        private.init(element);
        element.blur(private.blur);
        element.focus(private.focus);
      });
    }
  };

  var private = {
    init: function(field){
      if (field.val() == '' || field.val() == field.attr('title')){
        field.val(field.attr('title')).addClass('value-is-hint');
      }
    },
    blur: function(event){
      var field = jQuery(this);
      var settings = field.data(pluginName);
      if (field.val() == ''){
        field.val(field.attr('title')).addClass(settings.inputShowingHintClass);
      }
    },
    focus: function (event){
      var field = jQuery(this);
      var settings = field.data(pluginName);
      if (field.val() == field.attr('title')){
        field.val('').removeClass(settings.inputShowingHintClass);
      }
    }
  };

  $.addPlugin(pluginName, methods);

})( jQuery );

