/*
 * jQuery Fill/Clear Input Defaults plugin 0.3
 *
 *
 *
 */
(function($){
  $.fn.js_placeholder = function(opt) {
  
    var options = $.extend({
          contents: null,
          hideLabel: false
        }, opt),
        JS_placeholder = function(input,text) {
          if(!input.attr('value') || input.attr('value') == text)
          {
            input.val(text).addClass("autofilled");
          }
          input
            .focus(function(){
              if(input.attr('value') == text)
              {
                input.removeClass("autofilled").val('');
              }
            })
            .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') + '"]').toggle(!options.hideLabel).text();
      }
      each_el = new JS_placeholder($(this),text);
    });
    return this;
  }
})(jQuery)
