function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function GoogleMap(instanceID)
{if(instanceID){Widget.apply(this,arguments);}}
GoogleMap.prototype=new Widget();GoogleMap.prototype.constructor=GoogleMap;GoogleMap.prototype.widgetIdentifier="com-apple-iweb-widget-GoogleMap";GoogleMap.prototype.mapRequestTemplate='center=#{center}&zoomLevel=#{zoomLevel}&showZoom=#{showZoom}&mapType=#{mapType}&locatedAddress=#{locatedAddress}&locatedAddressPoint=#{locatedAddressPoint}&showInfo=#{showInfo}&language=#{language}';GoogleMap.prototype.iframeTemplate='<iframe id="#{instanceID}-iframe" name="#{instanceID}-iframe" src="#{mapURL}?#{mapRequest}" width="100%" height="100%" scrolling="no" marginheight="0" marginwidth="0" frameborder="0"></iframe>';GoogleMap.prototype.mapURL='http://www.mac.com/st/1/sharedassets/maps/iweb2/';GoogleMap.prototype.onload=function()
{var mapRequestTemplate=new Template(this.mapRequestTemplate);var mapRequest=mapRequestTemplate.evaluate({center:this.escapedPreferenceForKey("center"),zoomLevel:this.escapedPreferenceForKey("zoomLevel"),showZoom:this.escapedPreferenceForKey("showZoom"),mapType:this.escapedPreferenceForKey("mapType"),locatedAddress:this.escapedPreferenceForKey("locatedAddress"),locatedAddressPoint:this.escapedPreferenceForKey("locatedAddressPoint"),showInfo:this.escapedPreferenceForKey("showInfo"),language:this.escapedPreferenceForKey("language")});var iframeTemplate=new Template(this.iframeTemplate);var iframeText=iframeTemplate.evaluate({instanceID:this.instanceID,mapRequest:mapRequest,mapURL:this.mapURL});this.div().innerHTML=iframeText;if(this.preferences&&this.preferences.postNotification)
this.preferences.postNotification("BLWidgetIsSafeToDrawNotification",1);}
GoogleMap.prototype.escapedPreferenceForKey=function(key)
{var value=this.preferenceForKey(key);if(value!==undefined)
value=encodeURIComponent(value);return value;}

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()
{}

var widgets=[];var identifiersToStringLocalizations=[];function Widget(instanceID,widgetPath,sharedPath,sitePath,preferences,runningInApp)
{if(instanceID)
{this.instanceID=instanceID;this.widgetPath=widgetPath;this.sharedPath=sharedPath;this.sitePath=sitePath;this.preferences=preferences;this.runningInApp=(runningInApp===undefined)?false:runningInApp;this.onloadReceived=false;if(this.preferences&&this.runningInApp==true)
{this.preferences.widget=this;setTransparentGifURL(this.sharedPath.stringByAppendingPathComponent("None.gif"));}
this.div().widget=this;window[instanceID]=this;widgets.push(this);widgets[instanceID]=this;if(!this.constructor.instances)
{this.constructor.instances=new Array();}
this.constructor.instances.push(this);}}
Widget.prototype.div=function()
{var divID=this.instanceID;if(arguments.length==1)
{divID=this.instanceID+"-"+arguments[0];}
return $(divID);}
Widget.prototype.onload=function()
{this.onloadReceived=true;}
Widget.prototype.onunload=function()
{}
Widget.prototype.didBecomeSelected=function()
{}
Widget.prototype.didBecomeDeselected=function()
{}
Widget.prototype.didBeginEditing=function()
{}
Widget.prototype.didEndEditing=function()
{}
Widget.prototype.setNeedsDisplay=function()
{}
Widget.prototype.preferenceForKey=function(key)
{var value;if(this.preferences)
value=this.preferences[key];return value;}
Widget.prototype.initializeDefaultPreferences=function(prefs)
{var self=this;Object.keys(prefs).forEach(function(pref)
{if(self.preferenceForKey(pref)===undefined)
{self.setPreferenceForKey(prefs[pref],pref);}});}
Widget.prototype.setPreferenceForKey=function(preference,key,registerUndo)
{if(this.runningInApp)
{if(registerUndo===undefined)
registerUndo=true;if((registerUndo==false)&&this.preferences.disableUndoRegistration)
this.preferences.disableUndoRegistration();this.preferences[key]=preference;if((registerUndo==false)&&this.preferences.enableUndoRegistration)
this.preferences.enableUndoRegistration();}
else
{this.preferences[key]=preference;this.changedPreferenceForKey(key);}}
Widget.prototype.changedPreferenceForKey=function(key)
{}
Widget.prototype.postNotificationWithNameAndUserInfo=function(name,userInfo)
{if(window.NotificationCenter!==undefined)
{NotificationCenter.postNotification(new IWNotification(name,null,userInfo));}}
Widget.prototype.sizeWillChange=function()
{}
Widget.prototype.sizeDidChange=function()
{}
Widget.prototype.widgetWidth=function()
{var enclosingDiv=this.div();if(enclosingDiv)
return enclosingDiv.offsetWidth;else
return null;}
Widget.prototype.widgetHeight=function()
{var enclosingDiv=this.div();if(enclosingDiv)
return enclosingDiv.offsetHeight;else
return null;}
Widget.prototype.getInstanceId=function(id)
{var fullId=this.instanceID+"-"+id;if(arguments.length==2)
{fullId+=("$"+arguments[1]);}
return fullId;}
Widget.prototype.getElementById=function(id)
{var fullId=this.getInstanceId.apply(this,arguments);return $(fullId);}
Widget.prototype.localizedString=function(string)
{return LocalizedString(this.widgetIdentifier,string);}
Widget.onload=function()
{for(var i=0;i<widgets.length;i++)
{widgets[i].onload();}}
Widget.onunload=function()
{for(var i=0;i<widgets.length;i++)
{widgets[i].onunload();}}
function RegisterWidgetStrings(identifier,strings)
{identifiersToStringLocalizations[identifier]=strings;}
function LocalizedString(identifier,string)
{var localized=undefined;var localizations=identifiersToStringLocalizations[identifier];if(localizations===undefined)
{iWLog("warning: no localizations for widget "+identifier+", (key:"+string+")");}
else
{localized=localizations[string];}
if(localized===undefined)
{iWLog("warning: couldn't find a localization for '"+string+"' for widget "+identifier);localized=string;}
return localized;}
function WriteLocalizedString(identifier,string)
{document.write(LocalizedString(identifier,string));}
