(function($) {
  
  $.fn.ajaxify = function() {
    
    return this.each(function() {
      
      var $form = $(this),
          method = $form.attr('method').toLowerCase(),
          action = $form.attr('action');
      
      // when the form submits
      $form.submit(function(e) {
        
        // prevent submission
        e.preventDefault();

        // proxy all form stuff via ajax
        $[method](action, $form.serialize(), function(e) {
          // add a hook to tie in for success
          $form.trigger('success');
        });

      });
      
    });
    
  };
  
})(jQuery);
