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.replace('\/forums?','\/moms_forums?');;
                forumPostPageRequest = new ForumPostsPage(new DiscussionKey(discussKey), 1, 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.replace('\/forums?','\/moms_forums?');
                        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>';
                        html += '<h4><img src="' + postAvatar + '" border="0" width="35" alt="' + postUser + '" style="float:left; padding-right:5px;"><a href="' + postUrl + '" title="' + discussTitle + '">' + postBody +'</a></h4>';
                        html += '<p class="time-stamp">' + postUpdated + '</p>';
                        html += '</li>';
                        $('#mostRecentPosts').append(html);
                        });
                
        });
}
}


function featuredBlogger(blogkey, userId) {

var requestBatch = new RequestBatch();
var blogKey = new BlogKey(blogkey);
requestBatch.AddToRequest(blogKey);  
requestBatch.AddToRequest(new BlogPostPage(blogKey, 1, 1, 'TimeStampDescending', 'Published'));  
requestBatch.BeginRequest(serverUrl, function(responseBatch) {
console.log(responseBatch)
        var html = '';
        var activity = '';
        var Blogs = responseBatch.Responses[1].BlogPostPage.BlogPosts[0];
        var BlogInfo = responseBatch.Responses[0].Blog;
        //console.log('Blogs: ', Blogs);
        //console.log('BlogInfo: ', BlogInfo);
        var blogPostUrl =  Blogs.Url.replace('\/personas?','\/moms_blog?');
        var blogUrl =  BlogInfo.BlogUrl.replace('\/personas?','\/moms_blog?');
        var personaUrl = Blogs.PostAuthor.PersonaUrl.replace('\/personas?','\/moms_blog?');
        var numComments = Blogs.NumberOfComments;
        var numRecommends = Blogs.NumberOfRecommendations;
        
        if (numComments > 0 && numRecommends > 0) {
                activity = '('+ numComments + ') Comments | ('+ numRecommends + ') Recommends';
        }
        else {
                if (numComments > 0) {
                        activity = '('+ numComments + ') Comments';
                }
                if (numRecommends > 0) {
                        activity = '('+ numRecommends + ') Recommends';
                }
        }
        
        html += '<div class="fblogger-img">';
        html += '<a href="' + personaUrl + '"><img src="' + Blogs.PostAuthor.AvatarPhotoUrl + '" alt="Featured Blogger" border="0"\/><\/a>';
        html += '<\/div><!-- \/div.fblogger-img -->';
        html += '<div class="fblogger">';
        html += '<p class="fblogger-info"><a href="' + blogUrl + '">' + BlogInfo.Title + '<\/a><\/p>';
        html += '<h4><a href="' + blogPostUrl + '">' + Blogs.PostTitle + '<\/a><\/h4>';
        html += '<p class="time-stamp">' + Blogs.PostDate + '<br/ >' + activity + '<\/p>';
        html += '<\/div><!-- \/div.fblogger -->';

        $('#' + userId).append(html);
        
        });

}

function RecentGroups() {
var html = '';
var searchCategories = new Array();  
var activityDisco = new Activity('MostActive');  
var contentType = new ContentType('CommunityGroup');  
var requestBatch = new RequestBatch();
var activityRecommended = new DiscoverContentAction('',searchCategories,'',activityDisco,contentType,7,4, 'true');
requestBatch.AddToRequest(activityRecommended);
requestBatch.BeginRequest(serverUrl, groupCallBack);

function groupCallBack(responseBatch) {
        var Discover = responseBatch.Responses[0].DiscoverContentAction.DiscoveredContent;

        var result = jQuery.each(Discover, function () {

        html += '<li>';
        html += '<h4><img src="' + this.AvatarImageUrl + '" border="0" width="35" alt="' + this.Title + '" style="float:left; padding-right:5px;"><a href="http://www.star-telegram.com/moms_groups/?slPage=overview&slGroupKey=' + this.CommunityGroupKey.Key + '&slAcceptInvitation=false">' + this.Title + ':<\/a> ' + this.Description + '</h4>';
        html += '<p class="time-stamp">' + this.CommunityGroupStats.MemberCount + ' Members</p>';
        html += '</li>';

                
                });
        $('#mostRecentGroups').empty();
        $('#mostRecentGroups').append(html);
}
}

function MostRecentPhotos() {

var activityDisco = new Activity('Recent');  
var contentType = new ContentType('PublicPhoto');
var requestBatch = new RequestBatch();
activityRecommended = new DiscoverContentAction('','','',activityDisco,contentType,15,12);
requestBatch.AddToRequest(activityRecommended);
requestBatch.BeginRequest(serverUrl, getPhotos);

function getPhotos(responseBatch) { 	
        //console.log('Response', responseBatch);
        var Images = [];
        var i = -1;
		var iLen = Images.length;
        var Photos = responseBatch.Responses[0].DiscoverContentAction.DiscoveredContent;
        
        var result = jQuery.each(Photos, function () {
                i++;
                var li = '';
                if ((i+1)%4 == 0) { li = ' class="last"';}
                Images[i] = '<li' + li + '><div class="mb-img"><a href="' + this.PhotoUrl + '"><img src=' + this.Image.Medium + ' height="97"></a></div><div class="txt"><a href="' + this.PhotoUrl + '"><span class="icon icon-photo"></span>' + this.Title + '</a><p><a href="http://www.star-telegram.com/moms_gallery/index.html?plckGalleryID=' + this.GalleryKey.Key + '">View the gallery</a></p><p><a href="http://www.star-telegram.com/moms_photo_upload/index.html?plckGalleryID=' + this.GalleryKey.Key + '">Upload your photos</a></p></div></li>';
        });
        var PanelA = Images.slice(0,4);
        var PanelB = Images.slice(4,8);
        var PanelC = Images.slice(8,12);
        $('div.mb-panels').append('<div class="mb-panel"><ul>' + PanelA.join('') + '</ul></div>');
        if (iLen > 4) {
			$('div.mb-panels').append('<div class="mb-panel"><ul>' + PanelB.join('') + '</ul></div>');
			$('div.mb-controls').show();
		}
		if (iLen > 8) {
			$('div.mb-panels').append('<div class="mb-panel"><ul>' + PanelC.join('') + '</ul></div>');
			$('div.mb-controls').show();
		}
}
}
function featuredBlogList(keys, element) {

for(var i = 0, n = keys.length; i < n; i++) {
var blogkey = keys[i];

var requestBatch = new RequestBatch();
var blogKey = new BlogKey(blogkey);
requestBatch.AddToRequest(blogKey);  
requestBatch.AddToRequest(new BlogPostPage(blogKey, 1, 1, 'TimeStampDescending', 'Published'));  
requestBatch.BeginRequest(serverUrl, function(responseBatch) {
        // console.log('Blogger Response Batch: ', responseBatch);
        var html = '';
        var activity = '';
        if (responseBatch.Responses[1].BlogPostPage.BlogPosts[0]) {
        var Blogs = responseBatch.Responses[1].BlogPostPage.BlogPosts[0];
        var BlogInfo = responseBatch.Responses[0].Blog;
        
        var blogPostUrl =  Blogs.Url.replace('\/personas?','\/moms_blogs?');
        var blogUrl =  BlogInfo.BlogUrl.replace('\/personas?','\/moms_blogs?');
        var personaUrl = Blogs.PostAuthor.PersonaUrl.replace('\/personas?','\/moms_blogs?');
        var numComments = Blogs.NumberOfComments;
        var numRecommends = Blogs.NumberOfRecommendations;
        
        if (numComments > 0 && numRecommends > 0) {
                activity = '('+ numComments + ') Comments | ('+ numRecommends + ') Recommends';
        }
        else {
                if (numComments > 0) {
                        activity = '('+ numComments + ') Comments';
                }
                if (numRecommends > 0) {
                        activity = '('+ numRecommends + ') Recommends';
                }
        }
        
        if (Blogs.PostBody.length > 500) {
                Blogs.PostBody = Blogs.PostBody.substr(0, 500) + ' ...';
        }

        html += '<li><div class="fblogger-img">';
        html += '<a href="' + personaUrl + '"><img src="' + Blogs.PostAuthor.AvatarPhotoUrl + '" alt="Featured Blogger" border="0"\/><\/a>';
        html += '<\/div><!-- \/div.fblogger-img -->';
        html += '<div class="fblogger">';
        html += '<p class="fblogger-info"><a href="' + blogUrl + '">' + BlogInfo.Title + '<\/a><\/p>';
        html += '<h4><a href="' + blogPostUrl + '">' + Blogs.PostTitle + '<\/a><\/h4>';
        html += '<p class="time-stamp">' + Blogs.PostDate + '<br/ >' + activity + '<\/p>';
        html += '<\/div><!-- \/div.fblogger --></li>';

        $('ul#' + element).prepend(html);
        }
        });
}
}