function MostRecentForumPosts(forum) {

var activityDisco = new Activity('Recent');  
var contentType = new ContentType('Discussion');
var ParentKeys = new Array(new ForumKey(forum));
var requestBatch = new RequestBatch();
activityRecommended = new DiscoverContentAction('','','',activityDisco,contentType,14,4,'',ParentKeys);
requestBatch.AddToRequest(activityRecommended);
requestBatch.BeginRequest(serverUrl, getForumPost);

function getForumPost(responseBatch) {
        //console.log('Response', responseBatch);
        var Discussions = responseBatch.Responses[0].DiscoverContentAction.DiscoveredContent;
	$('#mostRecentPosts').empty();
        var result = jQuery.each(Discussions, function () {
                var html = '';
                var discussKey = this.ForumDiscussionKey.Key;
                var discussTitle = this.DiscussionTitle;
		            var discussUrl = this.DiscussionUrl;
                forumPostPageRequest = new ForumPostsPage(new DiscussionKey(discussKey), 3, 1, 'TimeStampDescending');
        	var requestBatch = new RequestBatch();
        	requestBatch.AddToRequest(forumPostPageRequest);
        	requestBatch.BeginRequest(serverUrl, function(responseBatch) {
                        //console.log('Post Info: ', responseBatch);
			var posts = responseBatch.Responses[0].ForumPostsPage.Posts[0];
                        var postUrl =  posts.PostUrl;
                        var postUser = posts.LiteUser.DisplayName;
			var postAvatar = posts.LiteUser.ImageUrl;
                        var postPersona = posts.LiteUser.PersonaUrl;
                        var postUpdated = posts.LastUpdated;
                        var postBody = posts.PostBody;
                        postBody = postBody.replace(/\[QUOTE\]/g,'\"');
                        postBody = postBody.replace(/\[\/QUOTE\]/g,'\" -- ');
                        var postTitle = posts.PostTitle;
        
                        if (postBody.length > 100) {
                        postBody = postBody.substr(0,100) + ' ...';
                        }
                        html = '';
                        html += '<li><b>' + discussTitle + '</b><br />';
                        html += '<b><a href="' + postPersona + '"><img src="' + postAvatar + '" border="0" width="35" alt="' + postUser + '" style="float:left; padding-right:5px;"></a><a href="' + postUrl + '">' + postBody +'</a></b>';
                        html += '<p class="time-stamp">' + postUpdated + '</p>';
                        html += '</li>';
                        $('#mostRecentPosts').append(html);
                        });
                
        });
}
}

