jQuery(document).ready(function($) {
	rafRebind();
});

function rafAddNewFriend() {
	// Retrieve parent TR element HTML code
	var html = jQuery(this).parent().parent().html();
	
	// Find numeric position and update to the next number
	var startingNum = html.match(/\[(\d+)\]/);
	var nextNum = parseInt(startingNum[1]) + 1;
	html = html.replace(/\[(\d+)\]/g, '[' + nextNum + ']');
	//alert(html);
	
	jQuery(this).hide();
	
	jQuery(this).parent().parent().addClass('testing');
	jQuery(this).parent().parent().after('<tr>' + html + '</tr>');
	rafRebind();
}

function rafRebind() {
	jQuery('.add-friend-button').unbind();
	jQuery('.add-friend-button').click(rafAddNewFriend);
}

