﻿/**
 * jQuery.placeholder - Placeholder plugin for input fields
 * Written by Blair Mitchelmore (blair DOT mitchelmore AT gmail DOT com)
 * Licensed under the WTFPL (http://sam.zoy.org/wtfpl/).
 * Date: 2008/10/14
 *
 * @author Blair Mitchelmore
 * @version 1.0.1
 *
 **/


(function($) {
  jQuery.fn.placeholder = function(options) {
    settings = jQuery.extend({
      onClass: 'focused',
      offClass: false
    }, options);

    return this.each(function() {
      
      var ph = $(this).attr('placeholder');
      if(typeof(ph) == 'string') $(this).val(ph);

      $(this).bind('focus', function(){

        var ph = $(this).attr('placeholder');
        if(typeof(ph) == 'string') 
          if($(this).val() == ph)
            $(this).val('');

        if(settings['onClass']) $(this).addClass(settings['onClass']);
        if(settings['offClass']) $(this).removeClass(settings['offClass']);
      
      }).bind('blur', function(){

        var ph = $(this).attr('placeholder');
        if(typeof(ph) == 'string') 
          if($(this).val().length == 0)
            $(this).val( ph );

        if(settings['onClass']) $(this).removeClass(settings['onClass']);
        if(settings['offClass']) $(this).addClass(settings['offClass']);
      });
    });
  };
})(jQuery);

