
NYX.DiscoWriter=function(idRoot,itemTemplate){NYX.util.obj.extend(this,NYX.TemplateTool);this.idRoot=idRoot;if(typeof template=="string"){this.template=template;}
else{template="@Nyx.PageTitle@";}
this.discoLimit=99;this.untitledText="Untitled";this.unnamedSection="";this.categoryJoin=", ";this.discoContent=[];this.prepareData=function(discoItem){var dataObj=this.flattenDaapiItem(discoItem);if(typeof discoItem.Categories=="object"){dataObj.Categories="";for(var catIdx=0;catIdx<discoItem.Categories.length;catIdx++){dataObj.Categories+=discoItem.Categories[catIdx].Name+this.categoryJoin;}
if(catIdx>0){dataObj.Categories=dataObj.Categories.substring(0,dataObj.Categories.length-this.categoryJoin.length);}}
if(typeof dataObj.PageTitle!="undefined"){if(NYX.util.string.isBlank(dataObj.PageTitle)){dataObj.PageTitle=this.untitledText;}}
if(discoItem.Section===null){dataObj.Section=this.unnamedSection;}else if(typeof discoItem.Section!="undefined"){if(NYX.util.string.isBlank(discoItem.Section.Name)){dataObj.Section=this.unnamedSection;}
else{dataObj.Section=discoItem.Section.Name;}}
return dataObj;};this.writeGui=function(daapiResponse){this.discoContent=daapiResponse;var discoData,itemIdx,loopLimit,html,targetElem;targetElem=this.getElem(this.DOM_TARGET_SUFFIX);if(targetElem!==null){this.initGui();loopLimit=this.discoContent.length<this.discoLimit?this.discoContent.length:this.discoLimit;for(itemIdx=0;itemIdx<loopLimit;itemIdx++){discoData=this.prepareData(this.discoContent[itemIdx]);switch(this.idRoot){case'RecDiscOutput':discoData.PageUrl+='?storylink=pluck_recommended';break;case'ComDiscOutput':discoData.PageUrl+='?storylink=pluck_commented';break;}
html=this.processTemplate(discoData,this.template);html=this.customizeItem(discoData,html,targetElem,itemIdx);targetElem.innerHTML+=html;}
this.finishGui();this.showTarget(targetElem);}};this.initGui=function(){return true;};this.finishGui=function(){return true;};this.customizeItem=function(dataObj,itemHtml,domElemThisWritesTo,itemIndex){return itemHtml;};};
function makeDiscoRequest(actype){var sections=[new Section("All")];var categories=[new Category("All")];var activity=new Activity(actype);var contentType=new ContentType("Article");var tiersToAllow=[new UserTier("All")];var contentAgeLimit=15;var maxToReturn=10;var discoveryAction=new DiscoverContentAction(sections,categories,tiersToAllow,activity,contentType,contentAgeLimit,maxToReturn,true);return discoveryAction;}
function daapiCallback(responseBatch){NYX.fixConsole();console.dir(responseBatch);if(typeof responseBatch.Responses[0]!="object"||typeof responseBatch.Responses[0].DiscoverContentAction!="object"){alert("Invalid response -- see the Firebug console (if you have one) to see what happened");}else{myGadgetCom.writeGui(responseBatch.Responses[0].DiscoverContentAction.DiscoveredContent);myGadgetRec.writeGui(responseBatch.Responses[1].DiscoverContentAction.DiscoveredContent);myGadgetAva.writeGui(responseBatch.Responses[2].User);}}
var myGadgetCom=new NYX.DiscoWriter("ComDiscOutput");myGadgetCom.discoLimit=10;myGadgetCom.unnamedSection="none";var myGadgetRec=new NYX.DiscoWriter("RecDiscOutput");myGadgetRec.discoLimit=10;myGadgetRec.unnamedSection="none";var myGadgetAva=new NYX.CurrentUser("AvatarOutput");var requestBatch=new RequestBatch();requestBatch.AddToRequest(makeDiscoRequest("Commented"));requestBatch.AddToRequest(makeDiscoRequest("Recommended"));requestBatch.AddToRequest(new UserKey());function pluckShowHide(hideID,showID){document.getElementById(hideID).style.display="none";document.getElementById(showID).style.display="block";}
