/*
 * jQuery Fill/Clear Input Defaults plugin 0.2
 *
 *
 *
 */
$.fn.js_placeholder = function(opt) {
  
  var options = $.extend({
        contents: null
      }, opt),
      JS_placeholder = function(input,text) {
        if(!input.attr('value') || input.attr('value') == text)
        {
          input.val(text).addClass("autofilled").focus(function(){
            if(input.attr('value') == text)
            {
              input.removeClass("autofilled").val('');
            }
          });
        }
        input.blur(function(){
          if(!input.attr('value'))
          {
            input.addClass("autofilled").val(text);
          }
        });
        $(input[0].form).submit(function(){
          if(input.val() == text)
          {
            input.val('');
          }
        });
      };
  
  $(this).filter('input:text, input:password, textarea').each(function(ind){
    var text = '',
        each_el;
    if(options.contents)
    {
      if(typeof(options.contents) == 'function')
      {
        text = options.contents(this,ind);
      }
      else
      {
        text = options.contents;
      }
    }
    else
    {
      text = $(this).attr('placeholder') ? $(this).attr('placeholder') : $('label[for="' + $(this).attr('id') + '"]').text();
    }
    each_el = new JS_placeholder($(this),text);
  });
  return this;
};

