function RecentGroups() {
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,14,3, 'true');
requestBatch.AddToRequest(activityRecommended);
requestBatch.BeginRequest(serverUrl, groupCallBack);

function groupCallBack(responseBatch) {
        var str = '<div class="story-list"><ul id="mostRecentGroups">';
        var Discover = responseBatch.Responses[0].DiscoverContentAction.DiscoveredContent;

        var result = jQuery.each(Discover, function () {
                
                str+='<li><img src="' + this.AvatarImageUrl + '" border=0> ';
                str+='<h4><a href="http://www.thatsracin.com/groups/?slPage=overview&slGroupKey=' + this.CommunityGroupKey.Key + '&slAcceptInvitation=false">' + this.Title + ': ' + this.Description + '<\/a><\/h4>';
                str+='<div class="time-stamp">' + this.CommunityGroupStats.MemberCount + ' Members<\/div><!-- \/div.time-stamp -->';
                str+='<\/li>';
                
                });
        str += '<li class="clear"></li></ul>';
        str += '<div class="group-link group-find"><h4><a href="http://www.thatsracin.com/groups/">Find a community group</a></h4></div>';
        str += '<div class="group-link group-start"><h4><a href="http://www.thatsracin.com/groups/?slPage=updateGroup&slGroupKey=&slCancelUrl=http%3A%2F%2Fwww.thatsracin.com%2Fgroups%2F">Start your own community group</a></h4></div>';        str += '</div>';

        $('#groups').append(str);
}
}

function RecentPosts() {
var searchCategories = new Array();  
var activityDisco = new Activity('Recent');  
var contentType = new ContentType('Discussion');  
var requestBatch = new RequestBatch();
activityRecommended = new DiscoverContentAction('',searchCategories,'',activityDisco,contentType,14,6);
requestBatch.AddToRequest(activityRecommended);
requestBatch.BeginRequest(serverUrl, forumCallBack);

function forumCallBack(responseBatch) {

        var str = '';
        var Discover = responseBatch.Responses[0].DiscoverContentAction.DiscoveredContent;
        //console.log('Discovered Content: ', Discover);
        jQuery.each(Discover, function () {

str+='<li>';
str+='<h4><a href="' + this.DiscussionUrl + '">' + this.DiscussionTitle.substr(0, 45) + '...<\/a><\/h4>';
str+='<div class="time-stamp">Posted ' + this.LastUpdated + '<\/div><!-- \/div.time-stamp -->';
str+='<\/li>';

                });
        $('#mostRecentPosts').append(str);
}
}

function getTally() {
    $(".comment_strip").each(function (e) {
      var foo = $(this).attr("class");
      foo = foo.split(" ", 2);
      var spanID = foo[1];
      var insert = '.' + spanID.replace('\.','\\.');
      var articleKey = new ArticleKey(spanID);  
      var requestBatch = new RequestBatch();  
      requestBatch.AddToRequest(articleKey);   
      requestBatch.BeginRequest(serverUrl, renderArticle);
      
            function renderArticle(responseBatch) {
            //console.log('span id: ', spanID);
            var pieces = new Array();
            var comment = '';
            var recommend = '';
            var endstr = '';
            var seperator = '';
            
            if (responseBatch.Responses.length == 0) {  
            //$("#" + spanID).text('[No comments]');  
            }
            else {
                var articleInfo = responseBatch.Responses[0].Article;
                if (articleInfo.Comments.NumberOfComments > 0 || articleInfo.Recommendations.NumberOfRecommendations > 0) {
                    pieces[0] = ' ( ';
                    pieces[4] = ' ) ';
                }
                if (articleInfo.Comments.NumberOfComments > 0 && articleInfo.Recommendations.NumberOfRecommendations > 0) {
                    pieces[2] = ' | ';
                }
                if (articleInfo.Comments.NumberOfComments > 0) {
                    pieces[1] = articleInfo.Comments.NumberOfComments + ' <img src="http://media.thatsracin.com/static/images/comment.gif">';
                }
                if (articleInfo.Recommendations.NumberOfRecommendations > 0) {
                    pieces[3] = articleInfo.Recommendations.NumberOfRecommendations + ' <img src="http://media.thatsracin.com/static/images/recommend.gif">';
                }
                var assembly = pieces.join('');
            //alert(insert);
            $(insert).html(assembly); 
            }
            
            }
    });
}