﻿/// <reference path="jquery-1.3.1-vsdoc.js" />

$(function() {

    var searchSections = new Array();  
    searchSections[0] = new Section("All"); 
    
    var searchCategories = new Array();  
    searchCategories[0] = new Category("All"); 
    
    var limitToContributors = new Array();  
    limitToContributors[0] = new UserTier("All");   

    var requestBatch = new RequestBatch();
    //requestBatch.AddToRequest(new DiscoverContentAction(searchSections, searchCategories, limitToContributors, new Activity("Rated"), new ContentType("Article"), 15, 5, true));
    //requestBatch.AddToRequest(new DiscoverContentAction(searchSections, searchCategories, limitToContributors, new Activity("Reviewed"), new ContentType("Article"), 15, 5, true));
    //requestBatch.AddToRequest(new DiscoverContentAction(searchSections, searchCategories, limitToContributors, new Activity("Recent"), new ContentType("Article"), 15, 5, true));
    //requestBatch.BeginRequest(serverUrl, clientCallBack);
    
});

function clientCallBack(responseBatch) {
    for (var i = 0; i < responseBatch.Responses.length; i++) {
        var response = responseBatch.Responses[i];
        userCallBackFunctionProcessor(response);
    }
}    

function userCallBackFunctionProcessor(response) {
    if (response.DiscoverContentAction != null) {
        processContent(response.DiscoverContentAction);
    }
}

function processContent(content) {
    if (content.DiscoveredContent.length > 0) {

        var divContainer = $("#" + content.Activity.Name);

        $.each(content.DiscoveredContent, function(i, item) {

            $.getJSON("/favourites/GetListingsDetail?publicListingId=" + item.ArticleKey.Key, null, function(data) {

              divContainer.append("<div><a href='"+data.PublicUrl+"'>"+data.Name+"</a></div>")

            });

        });
    }
}