(function() {  
  
  jQuery.fn.ajaxified_video_request_edit = function(options) {
    return this.each(function() {
      var that = $(this);
      that.click(function(event) {
    	  var parent = $('.my_videos .actions .request_edit_link').parent();
    	  _ajaxifiedFormSubmit(parent.next());
        parent.next().show();
    	  parent.empty();
    	  return false;
      });
    });
  };
  
  function _ajaxifiedFormSubmit(parent) {
  	var form = parent.children();
    form.submit(function() {
      form.find(':submit').hide();
      form.ajaxSubmit({
        url: form.attr('action') + '.js',
        success: function(html) { 
          form.replaceWith(html);
          _ajaxifiedFormSubmit(parent);
        },
        error: function () {
          alert('Senden fehlgeschlagen. Vielleicht klappt ein erneuter Versuch?');
          form.find(':submit').show();
        }
      });
      return false;
    });
  };
  
})(jQuery);


