WidgetBrowser=Class.create();WidgetBrowser.prototype={baseURI:"",categories:null,widgets:null,categoryColumn:null,widgetColumn:null,infoColumn:null,currentCategory:null,currentWidget:null,initialize:function(e,d,c){this.baseURI=e;
this.categories=[];this.widgets={};new Ajax.Request(e+d,{method:"get",onSuccess:this.showCategories.bind(this)});
var a=$(c);var b=a.getElementsByTagName("div");this.categoryColumn=b[0];this.widgetColumn=b[1];
this.infoColumn=b[2]},showCategories:function(b){var c=b.responseXML.getElementsByTagName("category");
var k=document.createElement("ul");this.categoryColumn.parentNode.replaceChild(k,this.categoryColumn);
this.categoryColumn=k;for(var e=0;e<c.length;e++){var f=c[e];var h=f.getElementsByTagName("title")[0].firstChild.nodeValue;
var l=f.getElementsByTagName("xml_file")[0].firstChild.nodeValue;var d=parseInt(f.getElementsByTagName("records")[0].firstChild.nodeValue);
var g=new Date(f.getElementsByTagName("pub_date")[0].firstChild.nodeValue);var a=new WidgetCategory(h,l,d,g);
this.categories.push(a);var m=function(i){return(function(){if(this.currentCategory==i){return
}this.closeCurrentCategory();if(!i.hasWidgets()){var n=this.baseURI+i.xmlFile+"?timestamp="+new Date().getTime();
new Ajax.Request(n,{method:"get",onSuccess:function(o){i.populateWidgets(o,this);
this.showWidgets(i)}.bind(this)})}else{this.showWidgets(i)}})};Event.observe(a.node,"click",m(a).bind(this));
Event.observe(a.node,"mouseover",a.mouseOver.bind(a));Event.observe(a.node,"mouseout",a.mouseOut.bind(a));
this.categoryColumn.appendChild(a.node)}if(this.widgetColumn.getElementsByTagName("p").length==0){var j=document.createElement("p");
Element.addClassName(j,"placeholder");j.appendChild(document.createTextNode("Select A Category"));
this.widgetColumn.appendChild(j)}},showWidgets:function(a){this.currentCategory=a;
var c=document.createElement("ul");this.widgetColumn.parentNode.replaceChild(c,this.widgetColumn);
this.widgetColumn=c;this.currentCategory.open(this.widgetColumn);if(this.infoColumn.getElementsByTagName("p").length==0){var b=document.createElement("p");
Element.addClassName(b,"placeholder");b.appendChild(document.createTextNode("Select A Widget"));
this.infoColumn.appendChild(b)}},showWidget:function(a){this.closeCurrentWidget();
this.currentWidget=a;this.currentWidget.open();this.infoColumn.parentNode.replaceChild(this.currentWidget.infoNode,this.infoColumn);
this.infoColumn=this.currentWidget.infoNode},closeCurrentCategory:function(){this.closeCurrentWidget();
if(this.currentCategory!=null){this.currentCategory.close();this.currentCategory=null
}},closeCurrentWidget:function(){if(this.currentWidget!=null){this.currentWidget.close();
this.currentWidget=null;var a=document.createElement("div");this.infoColumn.parentNode.replaceChild(a,this.infoColumn);
this.infoColumn=a}}};WidgetCategory=Class.create();WidgetCategory.prototype={title:"",xmlFile:"",recordCount:0,pubDate:null,node:null,widgets:null,initialize:function(d,a,b,c){this.title=d;
this.xmlFile=a;this.recordCount=b;this.pubDate=c;this.node=document.createElement("li");
this.node.appendChild(document.createTextNode(this.title+" ("+this.recordCount+")"));
this.widgets=[]},hasWidgets:function(){return(this.widgets.length>0)},open:function(a){Element.addClassName(this.node,"active");
for(var b=0;b<this.widgets.length;b++){a.appendChild(this.widgets[b].node)}},close:function(){Element.removeClassName(this.node,"active")
},mouseOver:function(){Element.addClassName(this.node,"hover")},mouseOut:function(){Element.removeClassName(this.node,"hover")
},populateWidgets:function(c,f){var j=c.responseXML.getElementsByTagName("download");
for(var d=0;d<j.length;d++){var g=j[d];var h=g.getAttribute("id");var a=g.getAttribute("name");
var e=new Widget(h,a);var b=function(i){return(function(){if(this.currentWidget==i){return
}i.open();if(typeof(this.widgets[i.idNumber])=="undefined"){var k=f.baseURI+"/nuggets/"+i.xmlFile+"?timestamp="+new Date().getTime();
new Ajax.Request(k,{method:"get",onSuccess:function(l){i.populate(l);this.widgets[i.idNumber]=i;
this.showWidget(i)}.bind(this)})}else{this.showWidget(i)}})};Event.observe(e.node,"click",b(e).bind(f));
Event.observe(e.node,"mouseover",e.mouseOver.bind(e));Event.observe(e.node,"mouseout",e.mouseOut.bind(e));
this.widgets.push(e)}}};Widget=Class.create();Widget.prototype={idNumber:null,title:"",xmlFile:"",version:"",pubDate:null,fileName:"",briefDescription:"",fileSize:0,downloadLink:"",license:"",imageHeight:0,imageWidth:0,image:"",node:null,infoNode:null,initialize:function(a,b){this.idNumber=a;
this.xmlFile=a.charAt(a.length-1)+"/"+a+".xml";this.title=b;this.node=document.createElement("li");
this.node.appendChild(document.createTextNode(this.title))},open:function(){Element.addClassName(this.node,"active")
},close:function(){Element.removeClassName(this.node,"active")},mouseOver:function(){Element.addClassName(this.node,"hover")
},mouseOut:function(){Element.removeClassName(this.node,"hover")},populate:function(g){var l=g.responseXML.getElementsByTagName("download")[0];
this.version=l.getElementsByTagName("name")[0].firstChild.nodeValue;this.pubDate=new Date(l.getElementsByTagName("pub_date")[0].firstChild.nodeValue);
this.fileName=l.getElementsByTagName("file_name")[0].firstChild.nodeValue;this.briefDescription=l.getElementsByTagName("brief_description")[0].firstChild.nodeValue;
this.fileSize=l.getElementsByTagName("file_size")[0].firstChild.nodeValue;this.downloadLink=l.getElementsByTagName("download_link")[0].firstChild.nodeValue;
this.license=l.getElementsByTagName("license")[0].firstChild.nodeValue;this.image=l.getElementsByTagName("image")[0].firstChild.nodeValue;
this.imageWidth=l.getElementsByTagName("image")[0].getAttribute("width");this.imageHeight=l.getElementsByTagName("image")[0].getAttribute("height");
if((this.imageHeight/2)>100){this.imageWidth=(this.imageWidth*100)/this.imageHeight;
this.imageHeight=100}else{this.imageHeight=this.imageHeight/2;this.imageWidth=this.imageWidth/2
}this.infoNode=document.createElement("div");var f=document.createElement("img");
f.setAttribute("src","http://images.apple.com"+this.image);f.setAttribute("width",this.imageWidth);
f.setAttribute("height",this.imageHeight);this.infoNode.appendChild(f);var o=document.createElement("h4");
o.appendChild(document.createTextNode(this.title));this.infoNode.appendChild(o);
var c=["January","February","March","April","May","June","July","August","September","October","November","December"];
var h=c[this.pubDate.getMonth()]+" "+this.pubDate.getDate()+", "+this.pubDate.getFullYear();
var d=document.createElement("p");Element.addClassName(d,"date");d.appendChild(document.createTextNode(h));
this.infoNode.appendChild(d);var k=document.createElement("p");Element.addClassName(k,"license");
k.appendChild(document.createTextNode(this.license));this.infoNode.appendChild(k);
var a=document.createElement("p");Element.addClassName(a,"download");var n=document.createElement("a");
n.setAttribute("href",this.downloadLink);Element.addClassName(n,"downloadbutton");
a.appendChild(n);var m=document.createElement("b");m.appendChild(document.createTextNode("Download"));
n.appendChild(m);var j=document.createElement("i");j.appendChild(document.createTextNode(this.fileSize));
n.appendChild(j);this.infoNode.appendChild(a);var p=document.createElement("p");
p.appendChild(document.createTextNode(this.briefDescription));this.infoNode.appendChild(p);
var e=document.createElement("a");e.setAttribute("href",this.fileName);Element.addClassName(e,"more-info");
e.appendChild(document.createTextNode("More Info..."));this.infoNode.appendChild(e)
}};

