var NavBar=Class.create(Widget,{widgetIdentifier:"com-apple-iweb-widget-NavBar",initialize:function($super,h,n,l,i,j,k){if(h){$super(h,n,l,i,j,k);if(!this.preferenceForKey("useStaticFeed")&&this.preferenceForKey("dotMacAccount")){var m=this.preferenceForKey("path-to-root");if(!m||m==""){m="./"}this.xml_feed=m+"?webdav-method=truthget&depth=infinity&ns=iweb&filterby=in-navbar"}else{this.xml_feed="feed.xml";if(this.sitePath){this.xml_feed=this.sitePath+"/"+this.xml_feed}}this.changedPreferenceForKey("navbar-css");this.regenerate()}},regenerate:function(){new Ajax.Request(this.xml_feed,{method:"get",onSuccess:this.populateNavItems.bind(this)});return true},getStyleElement:function(f){if(!this.styleElement){var d=document.getElementsByTagName("head")[0];if(d){var e=document.createElement("style");e.type="text/css";d.appendChild(e);this.styleElement=e}}return this.styleElement},substWidgetPath:function(c){var d=c.replace(/\$WIDGET_PATH/gm,this.widgetPath);return d},addCSSSelectorPrefix:function(c){var d="div#"+this.instanceID+" ";c=c.replace(/\/\*[^*]*\*+([^/][^*]*\*+)*\//gm,"");c=c.replace(/(^\s*|\}\s*)([^{]+)({[^}]*})/gm,function(m,n,k,i){var b=n;var a=k.split(",");for(var l=0;l<a.length;l++){b+=d+a[l];if(l+1<a.length){b+=","}}b+=i;return b});return c},changedPreferenceForKey:function(e){if(e=="navbar-css"){var g=this.preferenceForKey(e);if(!g){g=""}g=this.substWidgetPath(g);g=this.addCSSSelectorPrefix(g);var f=this.getStyleElement();if(f){if(!windowsInternetExplorer){var h=document.createTextNode(g);if(h){while(f.hasChildNodes()){f.removeChild(f.firstChild)}f.appendChild(h)}}else{f.styleSheet.cssText=g}}}},populateNavItems:function(u){var G;var w=ajaxGetDocumentElement(u);if(w){var D=this.getAtomFeedItems(w);var G=D.resultArray;var H=null;var A="NO";var t=null;if(this.runningInApp){t=/\.#current#.$/}else{H=this.preferenceForKey("current-page-GUID");A=this.preferenceForKey("isCollectionPage")}var v=this.div("navbar-list");var x=v.parentNode;$(x).ensureHasLayoutForIE();while(v.firstChild){v.removeChild(v.firstChild)}var E=this.preferenceForKey("path-to-root");if(!E||E==""){E="./"}for(var C=0;C<G.length;C++){var y=document.createElement("li");var z=document.createElement("a");var F=G[C].title;var r=G[C].GUID;F=F.replace(/ /g,"\u00a0")+" ";var s=G[C].url;if(!this.runningInApp&&!s.match(/^http:/i)){s=E+s}var B=this.runningInApp&&t.exec(unescape(new String(s)));if(B){s=s.replace(t,"")}if(r==H||B){y.className="current-page";if(!this.runningInApp&&A!="YES"){s=""}}else{y.className="noncurrent-page"}z.setAttribute("href",s);z.appendChild(document.createTextNode(F));y.appendChild(z);v.appendChild(y)}if(this.preferences&&this.preferences.postNotification){this.preferences.postNotification("BLWidgetIsSafeToDrawNotification",1)}}},getAtomFeedItems:function(x){var w=new Array;var y=new Array;if(x){var s="";var z=getFirstElementByTagName(x,"generator");if(z&&z.firstChild){s=allData(z)}var q,r;for(var A=x.firstChild;A;A=A.nextSibling){var B=null;if(!q&&(r=findChild(A,"site-navbar","urn:iweb:"))){q=allData(r).split(",");for(var t=0;t<q.length;t++){var o=q[t];y[""+o]=t}}if(A.nodeName=="entry"&&(B=findChild(A,"in-navbar","urn:iweb:"))){if(!B){continue}var o="";if(B.firstChild){o=""+allData(B)}else{iWLog("no navBarElt child")}if(o=="navbar-sort"){continue}var u="";var v=findChild(A,"title","urn:iweb:");if(!v){iWLog("No iWeb title");v=findChild(A,"title")}if(v&&v.firstChild){u=allData(v)}var p=getFirstElementByTagName(A,"link");url=p.getAttribute("href");if(!url&&linkElement.firstChild){url=allData(linkElement)}w[w.length]={title:u,url:url,GUID:o}}}}if(q){w=$(w).reject(function(a){return(y[a.GUID]===undefined)});w.sort(function(b,a){return y[b.GUID]-y[a.GUID]})}return{resultArray:w}},onload:function(){},onunload:function(){}});function findChild(j,f,i){var g;for(g=j.firstChild;g;g=g.nextSibling){if(g.localName==f||g.baseName==f){if(!i){return g}var h=g.namespaceURI;if(h==i){return g}}}return null}function getFirstElementByTagName(d,e){var f=d.getElementsByTagName(e);if(f.length){return f[0]}else{return findChild(d,e)}}function allData(d){d=d.firstChild;var c=d.data;while((d=d.nextSibling)){c+=d.data}return c};