/*
  This plugin looks through input form elements on a page.  For each input that has a "default" attribute,
  the value of that input will be set to the value of the "default" attribute.  In addition, the input
  will be given the class name, "defaulted".
*/
    
// jQuery Input Default Document

(function($) {

$.fn.inputdefault = function(opts) {

  var defaults = {
    param:    'default',
    newclass: 'defaulted'
  };

  // Extend our default options with those provided.
  var opts = $.extend(defaults, opts);

  return this
    .each(function() {
      addDefault( $(this) );
    })
    .focus(function() {
      removeDefault( $(this) );
    })
    .blur(function() {
      addDefault( $(this) );
    });

  function addDefault($obj) {
    if ($obj.val() == '' | $obj.val() == $obj.attr(opts.param) &&
    typeof( $obj.attr(opts.param) ) != 'undefined' )   {
      $obj.addClass(opts.newclass);
      $obj.val( $obj.attr(opts.param) );
    }
  };

  function removeDefault($obj) {
    if ($obj.hasClass(opts.newclass)) {
      $obj.val('');
      $obj.removeClass(opts.newclass);
    }
  };

};

})(jQuery);

