﻿
var curTGId;
function setupThumbGrids()
{

    $(".ThumbGrid").each(function (index) {        
       getThumbGrid($(this));      
       
    });
}

function getThumbGrid(tgTable)
{
  cellid = $(tgTable).attr("cellid");
  profileid = $(tgTable).attr("profileid");
  curTGId = tgTable;

  modToGet = moreCtlPath + "getContentCellFeed.aspx?cellid=" + cellid + "&profileid=" + profileid + "&basePath=" + moreDNNBasePath + "&pageSize=16&pageNum=1";    
  
  $.ajax({
            type: "GET",
            async: false,
            url: modToGet,
            dataType: "xml",
            success: parseThumbGridXml,            
            error: tgerror,
            cache: false
       });   
}

function tgerror(xreq,tstat,err)
{
//alert(tstat);
}

function parseThumbGridXml(xml)
{   
          
          feed = xml;
          $(xml).children("rss").children("channel").each(function() {           
            var channelTitle = $(this).children("title").text();                       
            if (channelTitle == "Cell Feed")
            {
              var itemiter = 1;
               $(this).children("item").each(function() {
                 
                 var tcells = parseInt($(curTGId).attr("totalCells"))                                  
                 if (itemiter <= tcells)
                 {
                   
                   var xmlItemId = $(this).children("itemid").text();
                   var xmlTitle = $(this).children("title").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 = $(curTGId).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\">"
                   }
                   cellid = cellid+"cell"+itemiter.toString();                                    
                   $("#"+cellid).html(linkstub+xmlImag+"<div class=\"thumbGridText\">"+xmlTitle+"</div></a>");
                 }
                   itemiter++;
                  
               });
               
            }
            
          });          
          
          if (window.setupLinkPopupLinks())
          {
             window.setupLinkPopupLinks();
          }
          
          if (window.setupArticlePopupLinks())
          {
            setupArticlePopupLinks()
          }
          
}
