
				
Type.registerNamespace("GG");
Type.registerNamespace("GG.GV");
GG.GV.G=function(control,feedID,readOnly){GG.GV.G.initializeBase(this,[control,"miniRoller sourceRoller"]);
this.feedID=feedID;
this.container.feedID=feedID;
this.container.gadgetInstance=this;
this.deleteLink=this.getChild("pageDelete","a");
this.dragHandle=this.getChild("pageMove","a");
this.editPanel=this.getChild("pageControls","span");
this.imageContainers=this.getChildren("imageContainer");
this.images=null;
this.readOnly=readOnly=="True";
GG.GV.GM.Instance.addGadget(this);
};
GG.GV.G.loadImages=function(feedID,list){var instance=GG.GV.GM.getGadgetObject(feedID);
instance.images=list;
if(GG.Modal.Instance)instance.loadImages();
else setTimeout(function(){ instance.loadImages();},1000);
};
GG.GV.G.onImageError=function(img){var instance=GG.GV.GM.getGadgetObject(img);
instance.tryNextImage(img);
};
GG.GV.G.onImageLoad=function(img){var instance=GG.GV.GM.getGadgetObject(img);
if(img.height<50&&img.height<50){instance.tryNextImage(img);
return;
}img.height=50;
img.width=50;
};
GG.GV.G.removeFullImage=function(img){document.body.removeChild(img.parentNode);
};
GG.GV.G.prototype={hideEditPanel:function(){this.editPanel.style.display="none";},showEditPanel:function(){this.editPanel.style.display="";},loadImages:function(){for(var i=0;i<this.imageContainers.length;i++){if(this.images[i].length>0&&this.images[i][0]!=""){this.imageContainers[i].innerHTML=String.format("<img src='{0}' onload='GG.GV.G.onImageLoad(this);' onerror='GG.GV.G.onImageError(this);' />",this.images[i][0]);
this.imageContainers[i].currentImageIndex=0;
}else {this.imageContainers[i].innerHTML="<img src='/images/default_article_img.gif' width='50' height='50' />";
}}},tryNextImage:function(img){var index=this.imageContainers.indexOf(GG.getParentByTag(img.parentNode,"div"));
var imageContainer=this.imageContainers[index];
var imageList=this.images[index];
if(imageContainer.currentImageIndex>=imageList.length){imageContainer.innerHTML="<img src='/images/default_article_img.gif' width='50' height='50' />";
return;
}imageContainer.currentImageIndex++;
imageContainer.innerHTML=String.format("<img src='{0}' onload='GG.GV.G.onImageLoad(this);' onerror='GG.GV.G.onImageError(this);' />",imageList[imageContainer.currentImageIndex]);
}};
GG.GV.G.registerClass("GG.GV.G",GG.BaseControl);
Type.registerNamespace("GG");
Type.registerNamespace("GG.M");
GG.M.GVFP=function(options){GG.M.GVFP.initializeBase(this,[options]);
};
GG.M.GVFP.prototype={load:function(html){this.body.innerHTML=html;
}};
GG.M.GVFP.registerClass("GG.M.GVFP",GG.Modal);
Type.registerNamespace("GG");
Type.registerNamespace("GG.GV");
GG.GV.GM=function(categoryID){this._categoryID=categoryID;
GG.GV.GM.Instance=this;
this.gadgetList=[];
this.containerList=[];
this.customizeLink=null;
this.customizePanel=$get("GG_GV_CustomizePanel");
this.isCustomizing=false;
this.preview=null;
this.sortablesCreated=false;
};
GG.GV.GM.RestoreDefaults=function(){var instance=GG.GV.GM.Instance;
if(confirm("Are you sure you wish to erase all your hard work and resync with the Grind Gods?"))GG.GVWS.RestoreDefaults( instance._categoryID,function(){GG.refreshPage();});
return false;
};
GG.GV.GM.processFavIcons=function(){var list=document.getElementsByClassName(document,"sourcesList","ul");
var sourceList=[];
for(var i=0;i<list.length;i++){if(list[i].faviconProcessed)continue;
var anchorList=list[i].getElementsByTagName("a");
for(var j=0;j<anchorList.length;j++){sourceList.push(anchorList[j]);
}list[i].faviconProcessed=true;
}for(var i=0;i<sourceList.length;i++){var a=sourceList[i];
var url=GG.getFaviconUrl(a.href);
if(url&&url.length!=0)a.innerHTML=["<img src='",url,"' alt='",a.title,"' onerror=\"this.style.display='none';\" height='16px' width='16px'  />",a.innerHTML].join('');
}};
GG.GV.GM.goSourcePage=function(pageIndex){var instance=GG.GV.GM.Instance;
GG.GVWS.GetSourcePage(pageIndex, instance._categoryID,function(html){instance.customizePanel.parentNode.innerHTML=html;
instance.customizePanel=$get("GG_GV_CustomizePanel");
instance.customizePanel.style.display="";
GG.GV.GM.processFavIcons();
});
return false;
};
GG.GV.GM.getGadgetObject=function( indexingObject){var returnValue=null;
if(typeof( indexingObject)=="number"){var feedID= indexingObject;
GG.GV.GM.Instance.gadgetList.each(function(gadget){if(gadget.feedID==feedID){returnValue=gadget;
return;
}});
}else {var control= indexingObject;
while(control!=null){if(control.gadgetInstance)return control.gadgetInstance;
control=control.parentNode;
}}if(returnValue==null){debugger;
alert("Could not find gadget instance for this thing.");
}return returnValue;
};
GG.GV.GM.closePreview=function(){var instance=GG.GV.GM.Instance;
if( instance.preview){instance.preview.modal.close();
instance.preview=null;
}return false;
};
GG.GV.GM.addFeed=function(feedID){var instance=GG.GV.GM.Instance;
var preview= instance.preview;
GG.GV.GM.closePreview();
var gadgetContainer=preview.gadgetContainer;
GG.GVWS.AddFeed( instance._categoryID,feedID,function(){ instance.saveLayout();});
var td= instance.containerList[0];
if(td.childNodes.length==0)td.appendChild(gadgetContainer);
else td.insertBefore(gadgetContainer,td.childNodes[0]);
preview.sourceControl.parentNode.removeChild(preview.sourceControl);
eval(preview.initCode);
var gadgetObject=GG.GV.GM.getGadgetObject(gadgetContainer);
if( instance.isCustomizing){instance.createSortables();
gadgetObject.showEditPanel();
}return false;
};
GG.GV.GM.previewFeed=function(control,feedID){if(!GG.CurrentUser.IsRegistered){GG.sendToLogin();return false;
}if(!GG.CurrentUser.IsVerified){GG.sendToUserVerification();return false;
}GG.GV.GM.closePreview();
var instance=GG.GV.GM.Instance;
var modal=new GG.M.GVFP({width:"350px"});
GG.GVWS.PreviewFeed(feedID,function(results){ instance.previewFeed(results,control,feedID,modal);});
return false;
};
GG.GV.GM.prototype={addGadget:function(gadget){this.gadgetList.push(gadget);
},previewFeed:function(results,control,feedID,modal){var html=results[0];
modal.load(html);
eval(results[1]);
var child=modal.getChild("miniRoller sourceRoller","div");
this.preview={modal:modal, initCode:results[1],sourceControl:control,gadgetContainer:child,feedID:feedID};
},removeGadget:function(childControl){if(confirm("Are you sure you wish to delete this gadget?")){var gadget=GG.GV.GM.getGadgetObject(childControl);
GG.GVWS.RemoveFeed(this._categoryID,gadget.feedID);
gadget.container.parentNode.removeChild(gadget.container);
var index=this.gadgetList.indexOf(gadget);
if( index>=0){this.gadgetList.splice(index,1);
}this.saveLayout();
}return false;
},addContainer:function(id,position){var control=$get(id);
control.horizontalPosition=position;
this.containerList.push($get(id));
},customize:function(childControl){if(!GG.CurrentUser.IsRegistered){GG.sendToLogin();return false;
}if(!GG.CurrentUser.IsVerified){GG.sendToUserVerification();return false;
}this.customizeLink=childControl;
this.customizeWrapper=this.customizeWrapper||GG.getParent(childControl,"customizeLinkWrapper closed");
if(this.isCustomizing){this.customizeWrapper.className="customizeLinkWrapper closed";
this.customizePanel.style.display="none";
this.customizeLink.innerHTML="Customize this page";
this.gadgetList.each(function(gadget){if(gadget.readOnly==false)gadget.hideEditPanel();
});
this.destorySortables();
}else {this.gadgetList.each(function(gadget){if(gadget.readOnly==false)gadget.showEditPanel();
});
this.customizeWrapper.className="customizeLinkWrapper open";
this.customizePanel.style.display="block";
this.createSortables();
}this.isCustomizing=!this.isCustomizing;
return false;
},destorySortables:function(){this.containerList.each(function(container){Sortable.destroy(container);
});
this.sortablesCreated=false;
},createSortables:function(){if(this.sortablesCreated)this.destorySortables();
var instance=this;
instance.containerList.each(function(container){Sortable.create(container,{tag:'div',handle:'pageMove',dropOnEmpty:true,constraint:false,containment: instance.containerList,scroll:window,onUpdate:function(){ instance.saveLayout();}});
});
this.sortablesCreated=true;
},initialize:function(){},saveLayout:function(){var list=[];
this.containerList.each(function(container){var sa=[];
for(var i=0;i<container.childNodes.length;i++){if(container.childNodes[i].feedID)sa.push(container.childNodes[i].feedID);
}list[container.horizontalPosition]=sa.join(":");
});
GG.GVWS.SaveLayout(this._categoryID,list);
}};
GG.GV.GM.registerClass("GG.GV.GM");
Sys.Application.notifyScriptLoaded();