﻿var ContentListCellId
var ContentListProfileId
var curContentList

function setupContentLists()
{

    $(".ContentList").each(function (index) {            
       getContentList($(this));             
    });
}

function getContentList(tgList)
{

   
  cellid = $(tgList).attr("cellid");
  profileid = $(tgList).attr("profileid");
  ContentListCellId = cellid;
  ContentListProfileId = profileid;
  curContentList = tgList;
  modToGet = moreCtlPath+"getContentCellFeed.aspx?cellid="+cellid+"&profileid="+profileid+"&basePath="+moreDNNBasePath+"&PageSize=16&PageNum=1";      
  $.ajax({
            type: "GET",
            async: false,
            url: modToGet,
            dataType: "xml",
            success: parseContentGridXml,            
            error: tgerror2,
            cache: false
       });   
}

function tgerror2(xreq,tstat,err)
{
//alert(tstat);
}


function parseContentGridXml(xml)
{   

            
          feed = xml;
          $(xml).children("rss").children("channel").each(function () {
              var channelTitle = $(this).children("title").text();
              if (channelTitle == "Cell Feed") {
                  var itemiter = 1;
                  $(curContentList).empty();

                  $(this).children("item").each(function () {

                      var xmlItemId = $(this).children("itemid").text();
                      var xmlItemIdVal = 0;
                      if (isNaN(xmlItemId) == false) xmlItemIdVal = parseInt(xmlItemId);
                      if (xmlItemIdVal > 0) {
                          var tItems = parseInt($(curContentList).attr("maxItems"))
                          if (itemiter <= tItems) {

                              var xmlItemId = $(this).children("itemid").text();
                              var xmlTitle = $(this).children("title").text();
                              var xmlSummary = $(this).children("[nodeName=InceptionPoint.CellFeed:ShortSummary]").text();
                              var xmlImag = $(this).children("[nodeName=InceptionPoint.CellFeed:Image]").text();
                              xmlImag = xmlImag.replace("//", "/");
                              var xmlItemType = $(this).children("[nodeName=InceptionPoint.CellFeed:ItemType]").text();
                              var xmlItemModuleId = $(this).children("[nodeName=InceptionPoint.CellFeed:ItemModuleId]").text();
                              var cellid = $(curContentList).attr("id")
                              var linkstub = "<a ";
                              if (xmlItemType == 'zLinks') {
                                  linkstub += "profilerModuleId=\"" + xmlItemModuleId + "\" profilerItemId=\"" + xmlItemId + "\" linkitemid=\"" + xmlItemId + "\" class=\"profileCollect zLinkStub\">"
                              }
                              else if (xmlItemType == 'Popup Articles') {
                                  linkstub += "profilerModuleId=\"" + xmlItemModuleId + "\" profilerItemId=\"" + xmlItemId + "\" articleitemid=\"" + xmlItemId + "\" class=\"profileCollect articlePopupLink\">"
                              }
                              var newli = "<li>";
                              newli += linkstub;

                              newli += xmlImag;
                              newli += "<span class=\"ContentListTitle\">" + xmlTitle + "</span>";
                              newli += "<span class=\"ContentListSummary\">" + xmlSummary + "</span>";
                              newli += "</a>";
                              newli += "</li>";
                              $(curContentList).append(newli);

                              //$("#"+cellid).html(linkstub+xmlImag+"<div class=\"thumbGridText\">"+xmlTitle+"</div></a>");
                          }
                          itemiter++;
                      }
                  });


              }
          });          
          
          $(curContentList).append("<li><br/><div cellid=\""+ContentListCellId+"\" profileid=\""+ContentListProfileId+"\" class=\"morepopup contentlistmore\">More</div></li>");
          setupMorePopupLinks();
          //$(curContentList).append("<br/><div cellid=\"" + ContentListCellId.ToString() + "\" profileid=\"" + ContentListProfileId.ToString() + "\" class=\"morepopup\" >More</div>");
          
          
          if (window.setupLinkPopupLinks())
          {
             window.setupLinkPopupLinks();
          }
          
          if (window.setupArticlePopupLinks())
          {
              setupArticlePopupLinks()
          }
}
