(function($){

    function obj_copy(obj){
      var out = {};
      for (i in obj) {
        if (typeof obj[i] == 'object') {
          out[i] = jQuery.extend(true, {}, obj[i]);
        }
        else
          out[i] = obj[i];
      }
      return out;
    }

    $.fn.extend({

      storeEvents:function(){
          this.each(function(){
              $.data(this,'storedEvents',obj_copy($(this).data('events')));
          });
          return this;
      },

      restoreEvents:function(){
          this.each(function(){
              var events = $.data(this,'storedEvents');
              if (events){
                  $(this).unbind();
                  for (var type in events){
                      for (var handler in events[type]){
                          $.event.add(
                              this, 
                              type, 
                              events[type][handler], 
                              events[type][handler].data);
                      }
                  }
              }
          });
          return this;
      }

    });
})(jQuery);