Index: src/bp-templates/bp-legacy/js/buddypress.js
===================================================================
--- src/bp-templates/bp-legacy/js/buddypress.js	(revision 11299)
+++ src/bp-templates/bp-legacy/js/buddypress.js	(working copy)
@@ -116,7 +116,7 @@
 		var last_date_recorded = 0,
 			button = jq(this),
 			form   = button.closest('form#whats-new-form'),
-			inputs = {}, post_data;
+			inputs = {}, post_data, activity_wrapper;
 
 		// Get all inputs and organize them into an object {name: value}
 		jq.each( form.serializeArray(), function( key, input ) {
@@ -148,10 +148,11 @@
 		form.addClass('submitted');
 
 		/* Default POST values */
+		activity_wrapper = jq(this).closest('div.activity');
 		object = '';
 		item_id = jq('#whats-new-post-in').val();
 		content = jq('#whats-new').val();
-		firstrow = jq( '#buddypress ul.activity-list li' ).first();
+		firstrow = jq( '#buddypress ul.activity-list li', activity_wrapper ).first();
 		activity_row = firstrow;
 		timestamp = null;
 
@@ -197,10 +198,10 @@
 				form.prepend( response.substr( 2, response.length ) );
 				jq( '#' + form.attr('id') + ' div.error').hide().fadeIn( 200 );
 			} else {
-				if ( 0 === jq('ul.activity-list').length ) {
+				if ( 0 === jq('ul.activity-list', activity_wrapper).length ) {
 					jq('div.error').slideUp(100).remove();
 					jq('#message').slideUp(100).remove();
-					jq('div.activity').append( '<ul id="activity-stream" class="activity-list item-list">' );
+					jq('div.activity', activity_wrapper).append( '<ul id="activity-stream" class="activity-list item-list">' );
 				}
 
 				if ( firstrow.hasClass( 'load-newest' ) ) {
@@ -207,7 +208,7 @@
 					firstrow.remove();
 				}
 
-				jq('#activity-stream').prepend(response);
+				jq('#activity-stream', activity_wrapper).prepend(response);
 
 				if ( ! last_date_recorded ) {
 					jq('#activity-stream li:first').addClass('new-update just-posted');
@@ -255,7 +256,7 @@
 	/* List tabs event delegation */
 	jq('div.activity-type-tabs').on( 'click', function(event) {
 		var target = jq(event.target).parent(),
-			scope, filter;
+			scope, filter, activity_wrapper;
 
 		if ( event.target.nodeName === 'STRONG' || event.target.nodeName === 'SPAN' ) {
 			target = target.parent();
@@ -268,6 +269,7 @@
 			path: '/',
 			secure: ( 'https:' === window.location.protocol )
 		} );
+		activity_wrapper = jq(target).closest('div.activity');
 
 		/* Activity Stream Tabs */
 		scope  = target.attr('id').substr( 9, target.attr('id').length );
@@ -277,7 +279,7 @@
 			jq( '#' + target.attr('id') + ' a strong' ).remove();
 		}
 
-		bp_activity_request(scope, filter);
+		bp_activity_request(scope, filter, activity_wrapper);
 
 		return false;
 	});
@@ -286,7 +288,7 @@
 	jq('#activity-filter-select select').change( function() {
 		var selected_tab = jq( 'div.activity-type-tabs li.selected' ),
 			filter = jq(this).val(),
-			scope;
+			scope, activity_wrapper;
 
 		if ( !selected_tab.length ) {
 			scope = null;
@@ -294,7 +296,8 @@
 			scope = selected_tab.attr('id').substr( 9, selected_tab.attr('id').length );
 		}
 
-		bp_activity_request(scope, filter);
+		activity_wrapper = jq(selected_tab).closest('div.activity');
+		bp_activity_request(scope, filter, activity_wrapper);
 
 		return false;
 	});
@@ -304,8 +307,9 @@
 		var target = jq(event.target),
 			type, parent, parent_id,
 			li, id, link_href, nonce, timestamp,
-			oldest_page, just_posted;
+			oldest_page, just_posted, activity_wrapper;
 
+		activity_wrapper = target.closest('div.activity');
 		/* Favoriting activity stream items */
 		if ( target.hasClass('fav') || target.hasClass('unfav') ) {
 			/* Bail if a request is in progress */
@@ -318,7 +322,6 @@
 			parent_id = parent.attr('id').substr( 9, parent.attr('id').length );
 
 			target.addClass('loading');
-
 			jq.post( ajaxurl, {
 				action: 'activity_mark_' + type,
 				'cookie': bp_get_cookies(),
@@ -353,7 +356,7 @@
 
 					if ( !Number( jq('.item-list-tabs ul #activity-favorites span').html() ) ) {
 						if ( jq('.item-list-tabs ul #activity-favorites').hasClass('selected') ) {
-							bp_activity_request( null, null );
+							bp_activity_request( null, null, activity_wrapper );
 						}
 
 						jq('.item-list-tabs ul #activity-favorites').remove();
@@ -440,7 +443,7 @@
 				bp_ajax_request.abort();
 			}
 
-			jq('#buddypress li.load-more').addClass('loading');
+			jq('#buddypress li.load-more', activity_wrapper).addClass('loading');
 
 			if ( null === jq.cookie('bp-activity-oldestpage') ) {
 				jq.cookie('bp-activity-oldestpage', 1, {
@@ -452,7 +455,7 @@
 			oldest_page = ( jq.cookie('bp-activity-oldestpage') * 1 ) + 1;
 			just_posted = [];
 
-			jq('.activity-list li.just-posted').each( function(){
+			jq('.activity-list li.just-posted', activity_wrapper).each( function(){
 				just_posted.push( jq(this).attr('id').replace( 'activity-','' ) );
 			});
 
@@ -472,12 +475,12 @@
 			bp_ajax_request = jq.post( ajaxurl, load_more_args,
 			function(response)
 			{
-				jq('#buddypress li.load-more').removeClass('loading');
+				jq('#buddypress li.load-more', activity_wrapper).removeClass('loading');
 				jq.cookie( 'bp-activity-oldestpage', oldest_page, {
 					path: '/',
 					secure: ( 'https:' === window.location.protocol )
 				} );
-				jq('#buddypress ul.activity-list').append(response.contents);
+				jq('#buddypress ul.activity-list', activity_wrapper).append(response.contents);
 
 				target.parent().hide();
 			}, 'json' );
@@ -508,7 +511,7 @@
 			} );
 
 			// Now the stream is cleaned, prepend newest
-			jq( '#buddypress ul.activity-list' ).prepend( newest_activities );
+			jq( '#buddypress ul.activity-list', activity_wrapper ).prepend( newest_activities );
 
 			// reset the newest activities now they're displayed
 			newest_activities = '';
@@ -521,10 +524,11 @@
 			link_id = target.parent().attr('id').split('-'),
 			a_id    = link_id[3],
 			type    = link_id[0], /* activity or acomment */
-			inner_class, a_inner;
-
+			inner_class, a_inner,
+			activity_wrapper;
+		activity_wrapper = target.closest('div.activity');
 		inner_class = type === 'acomment' ? 'acomment-content' : 'activity-inner';
-		a_inner = jq('#' + type + '-' + a_id + ' .' + inner_class + ':first' );
+		a_inner = jq('#' + type + '-' + a_id + ' .' + inner_class + ':first', activity_wrapper );
 		jq(target).addClass('loading');
 
 		jq.post( ajaxurl, {
@@ -557,8 +561,11 @@
 			ajaxdata,
 			ak_nonce,
 			show_all_a, new_count,
-			link_href, comment_li, nonce;
+			link_href, comment_li, nonce,
+			activity_wrapper;
 
+			activity_wrapper = target.closest('div.activity');
+
 		/* Comment / comment reply links */
 		if ( target.hasClass('acomment-reply') || target.parent().hasClass('acomment-reply') ) {
 			if ( target.parent().hasClass('acomment-reply') ) {
@@ -568,9 +575,10 @@
 			id  = target.attr('id');
 			ids = id.split('-');
 
+
 			a_id = ids[2];
 			c_id = target.attr('href').substr( 10, target.attr('href').length );
-			form = jq( '#ac-form-' + a_id );
+			form = jq( '#ac-form-' + a_id, activity_wrapper );
 
 			form.css( 'display', 'none' );
 			form.removeClass('root');
@@ -584,9 +592,9 @@
 			});
 
 			if ( ids[1] !== 'comment' ) {
-				jq('#acomment-' + c_id).append( form );
+				jq('#acomment-' + c_id, activity_wrapper).append( form );
 			} else {
-				jq('#activity-' + a_id + ' .activity-comments').append( form );
+				jq('#activity-' + a_id + ' .activity-comments', activity_wrapper).append( form );
 			}
 
 			if ( form.parent().hasClass( 'activity-comments' ) ) {
@@ -598,7 +606,7 @@
 				offset:-100,
 				easing:'swing'
 			} );
-			jq('#ac-form-' + ids[2] + ' textarea').focus();
+			jq('#ac-form-' + ids[2] + ' textarea', activity_wrapper).focus();
 
 			return false;
 		}
@@ -616,10 +624,10 @@
 				comment_id = form_id[2];
 			}
 
-			content = jq( '#' + form.attr('id') + ' textarea' );
+			content = jq( '#' + form.attr('id') + ' textarea', activity_wrapper );
 
 			/* Hide any error messages */
-			jq( '#' + form.attr('id') + ' div.error').hide();
+			jq( '#' + form.attr('id') + ' div.error', activity_wrapper).hide();
 			target.addClass('loading').prop('disabled', true);
 			content.addClass('loading').prop('disabled', true);
 
@@ -663,15 +671,15 @@
 						form.children('textarea').val('');
 						activity_comments.parent().addClass('has-comments');
 					} );
-					jq( '#' + form.attr('id') + ' textarea').val('');
+					jq( '#' + form.attr('id') + ' textarea', activity_wrapper).val('');
 
 					/* Increase the "Reply (X)" button count */
-					jq('#activity-' + form_id[2] + ' a.acomment-reply span').html( Number( jq('#activity-' + form_id[2] + ' a.acomment-reply span').html() ) + 1 );
+					jq('#activity-' + form_id[2] + ' a.acomment-reply span', activity_wrapper).html( Number( jq('#activity-' + form_id[2] + ' a.acomment-reply span', activity_wrapper).html() ) + 1 );
 
 					// Increment the 'Show all x comments' string, if present
 					show_all_a = activity_comments.find('.show-all').find('a');
 					if ( show_all_a ) {
-						new_count = jq('li#activity-' + form_id[2] + ' a.acomment-reply span').html();
+						new_count = jq('li#activity-' + form_id[2] + ' a.acomment-reply span', activity_wrapper).html();
 						show_all_a.html( BP_DTheme.show_x_comments.replace( '%d', new_count ) );
 					}
 				}
@@ -715,7 +723,7 @@
 				if ( response[0] + response[1] === '-1' ) {
 					comment_li.prepend( jq( response.substr( 2, response.length ) ).hide().fadeIn( 200 ) );
 				} else {
-					var children  = jq( '#' + comment_li.attr('id') + ' ul' ).children('li'),
+					var children  = jq( '#' + comment_li.attr('id') + ' ul' , activity_wrapper).children('li'),
 						child_count = 0,
 						count_span, new_count, show_all_a;
 
@@ -757,7 +765,7 @@
 			target.addClass('loading');
 
 			// Remove any error messages
-			jq( '.activity-comments ul div.error' ).remove();
+			jq( '.activity-comments ul div.error', activity_wrapper ).remove();
 
 			// Reset the form position
 			comment_li.parents( '.activity-comments' ).append( comment_li.parents( '.activity-comments' ).children( 'form' ) );
@@ -775,7 +783,7 @@
 					comment_li.prepend( jq( response.substr( 2, response.length ) ).hide().fadeIn( 200 ) );
 
 				} else {
-					var children  = jq( '#' + comment_li.attr( 'id' ) + ' ul' ).children( 'li' ),
+					var children  = jq( '#' + comment_li.attr( 'id' ) + ' ul', activity_wrapper ).children( 'li' ),
 						child_count = 0,
 						parent_li;
 
@@ -788,7 +796,7 @@
 
 					// Decrease the "Reply (X)" button count
 					parent_li = comment_li.parents( '#activity-stream > li' );
-					jq( '#' + parent_li.attr( 'id' ) + ' a.acomment-reply span' ).html( jq( '#' + parent_li.attr( 'id' ) + ' a.acomment-reply span' ).html() - ( 1 + child_count ) );
+					jq( '#' + parent_li.attr( 'id' ) + ' a.acomment-reply span', activity_wrapper ).html( jq( '#' + parent_li.attr( 'id' ) + ' a.acomment-reply span' ).html() - ( 1 + child_count ) );
 				}
 			});
 
@@ -1978,7 +1986,7 @@
 }
 
 /* Activity Loop Requesting */
-function bp_activity_request(scope, filter) {
+function bp_activity_request(scope, filter, activity_wrapper) {
 	/* Save the type and filter to a session cookie */
 	if ( null !== scope ) {
 		jq.cookie( 'bp-activity-scope', scope, {
@@ -2024,7 +2032,7 @@
 	{
 		jq('.widget_bp_activity_widget h2 span.ajax-loader').hide();
 
-		jq('div.activity').fadeOut( 100, function() {
+		jq('div.activity', activity_wrapper ).fadeOut( 100, function() {
 			jq(this).html(response.contents);
 			jq(this).fadeIn(100);
 
