$(function(){
  $.placeholder = {
    className: '_placeholder',

    supportedNatively: function() {
      var testInput = document.createElement('input');
      return 'placeholder' in testInput;
    },
    
    backwardsCompatibility: function() {
      if (!$.placeholder.supportedNatively()) {
        $(window).unload(function() {
          $('input.' + $.placeholder.className).val('');
        });
        
        $('input[placeholder]').each(function() {
          var $this = $(this);
          var placeholder = $this.attr('placeholder');
          
          $this.blur(function() {
            if ($this.val() == '') {
              $this.addClass($.placeholder.className).val(placeholder);
            }
          }).focus(function() {
            if ($this.hasClass($.placeholder.className)) {
              $this.val('').removeClass($.placeholder.className);
            }
          }).parents('form:first').submit(function() {
            $this.triggerHandler('focus');
          }).end().triggerHandler('blur');
        });
      }
    }
  };
  
  $.placeholder.backwardsCompatibility();
});