$(document).ready(function() {
  $.inputhelp.init($(".inputhelp"), {initClass:"dimmed"});
});

// Add help text into an input box which goes away when focused.
$.inputhelp = {
  init : function(inputElement, options) {

    inputElement.each(function() {
      var self = $(this);
      var initText = options.initText || self.attr('title') || '';

      self.focus(
          function() {
            if(self.val() == initText) {
              self.val('');
            }
            if(options.initClass) {
              self.removeClass(options.initClass); 
            }
          } 
        );
      self.blur(
          function() { 
            if (self.val() == "" || self.val() == initText) {
              if (options.initClass) {
                self.addClass(options.initClass);
              }
              self.val(initText);
            }
          }
        );
      self.parents('form').submit(function() {
          if (self.val() == initText) {
            self.val('');
          }
        }
      );
      self.blur();
    });
  }
};

