if(typeof (PageTreeManager)=="undefined"){var PageTreeManager=(function(){var L=[];
function O(U){if(window.AJS&&AJS.messages&&AJS.messages.error&&document.getElementById("aui-message-bar")){AJS.messages.error({body:U});
$("#aui-message-bar a[href]").attr("target","_blank")
}else{alert(window.AJS?AJS("span").html(U).text():U)
}}function P(U,V){return"pagetree"+U+"_"+V
}var E={computer:{dashboard:["workplace.png","workplace.png"],space:["folder_closed.png","folder.png"],page:["document_plain.png","document_plain.png"],recentpage:["document_plain_new.png","document_plain_new.png"],homepage:["home.png","home.png"],blogpost:["calendar.png","calendar.png"],recentblogpost:["calendar_preferences.png","calendar_preferences.png"],loading:["view.png","view.png"]},builder:{dashboard:["presentation.png","presentation.png"],space:["earth2.png","earth2.png"],page:["document.png","document.png"],recentpage:["document_new.png","document_new.png"],homepage:["home.png","home.png"],blogpost:["news.png","news.png"],recentblogpost:["news_new.png","news_new.png"],loading:["view.png","view.png"]},website:{dashboard:["home.png","home.png"],space:["earth2.png","earth2.png"],page:["document_plain.png","document_plain.png"],recentpage:["document_plain_new.png","document_plain_new.png"],homepage:["house.png","house.png"],blogpost:["date-time.png","date-time.png"],recentblogpost:["date-time_preferences.png","date-time_preferences.png"],loading:["view.png","view.png"]},bookshelf:{dashboard:["books.png","books.png"],space:["book_blue.png","book_open.png"],page:["document_text.png","document_text.png"],recentpage:["document_new.png","document_new.png"],homepage:["book_open2.png","book_open2.png"],blogpost:["document_time.png","document_time.png"],recentblogpost:["document_new.png","document_new.png"],loading:["view.png","view.png"]}};
var T="/download/resources/com.adaptavist.confluence.themes.sitebuilder:pagetree2/icons/";
var M="";
function J(V,U){if(E[V]!=null&&E[V][U]!=null){return M+T+E[V][U][0]+","+M+T+E[V][U][1]
}return null
}function Q(U,V){return(U.id>=V.id)
}function S(U,V){return(U.capt>=V.capt)
}function A(U,V){return(U.xtra.sortid>=V.xtra.sortid)
}var H={dashboard:S,space:null,page:null,recentpage:null,homepage:null,blogpost:Q,recentblogpost:Q};
function F(V,U){return function(X){var e=L[V];
if(e!=null){e.children[U]=X;
var f=e.tree;
var c=P(V,U);
if(f.getNodeById(c)!=null){f.remove(c+"_loading");
if(X!=null){var b=X.length;
X=X.reverse();
var Y;
var a;
var W;
var Z;
while(-1<--b){W=X[b];
Y=P(V,W.id);
a=(e.openpage)?W.url:"";
W.treeId=V;
Z=f.add(Y,c,W.title,a,J(e.iconStyle,W.type),false,false,W,(e.titletip)?W.title:W.tooltip);
Z.sortFunc=H[W.type];
f.setDrag(Y,e.allowdrag&&(W.type=="page")&&W.editPermission,false);
f.setDrop(Y,e.allowdrag&&(W.type=="page"||W.type=="homepage"||W.type=="space")&&W.createPermission,false);
if(W.hasChildren){f.add(Y+"_loading",Y,"loading...","",J(e.iconStyle,"loading"))
}}}f.reloadNode(c);
f.expandNode(c);
if(e.selectNode!=null&&e.selectNode==U){f.selectNodeById(c);
f.treeOnClick(null,U);
e.selectNode=null
}if(e.preload.length){var d=e.preload.shift();
G(d,V,e);
e.selectNode=d
}}}}
}function G(U,V,W){jQuery.ajax({url:AJS.Confluence.getContextPath()+"/plugins/builder/pagetree/children.action",data:{page:U,permissions:W.allowdrag,sort:W.sort,reverse:W.reverse},dataType:"json",cache:false,success:F(V,U)})
}function N(U,V){U.opt.trg=V.target;
U.opt.icon=V.showIcons;
U.opt.editable=false;
U.opt.sort="asc";
U.opt.selRow=(V.selectionMode=="row");
U.opt.oneExp=V.autoCollapse;
U.opt.indent=V.indent;
U.opt.hideRoot=!V.showRoot;
switch(V.branchStyle){default:case"plus-lines":break;
case"plus-nolines":U.ico.pnb=U.defImgPath+"plusnl.gif";
U.ico.pb=U.defImgPath+"plusnl.gif";
U.ico.mnb=U.defImgPath+"minusnl.gif";
U.ico.mb=U.defImgPath+"minusnl.gif";
U.ico.lnb=U.defImgPath+"blank.gif";
U.ico.lb=U.defImgPath+"blank.gif";
U.ico.lin=U.defImgPath+"blank.gif";
break;
case"ball-lines":U.ico.pnb=U.defImgPath+"bulclpsnb.gif";
U.ico.pb=U.defImgPath+"bulclpsb.gif";
U.ico.mnb=U.defImgPath+"bulexpnb.gif";
U.ico.mb=U.defImgPath+"bulexpb.gif";
break;
case"ball-nolines":U.ico.pnb=U.defImgPath+"bulclpsnl.gif";
U.ico.pb=U.defImgPath+"bulclpsnl.gif";
U.ico.mnb=U.defImgPath+"bulexpnl.gif";
U.ico.mb=U.defImgPath+"bulexpnl.gif";
U.ico.lnb=U.defImgPath+"blank.gif";
U.ico.lb=U.defImgPath+"blank.gif";
U.ico.lin=U.defImgPath+"blank.gif";
break;
case"arrow":U.ico.pnb=U.defImgPath+"arrowright.gif";
U.ico.pb=U.defImgPath+"arrowright.gif";
U.ico.mnb=U.defImgPath+"arrowdown.gif";
U.ico.mb=U.defImgPath+"arrowdown.gif";
U.ico.lnb=U.defImgPath+"blank.gif";
U.ico.lb=U.defImgPath+"blank.gif";
U.ico.lin=U.defImgPath+"blank.gif";
break
}}function I(U){return function(X){var W=L[U];
if(W!=null){var V=W.tree.getNodeById(X);
if(V!=null&&V.xtra!=null&&V.xtra.id!=null&&W.children[V.xtra.id]==null){G(V.xtra.id,U,W)
}}}
}var B={};
function C(U){return function(Z,a){var Y=L[U];
var W=B[Y.name];
if(Y!=null&&W!=null){var X=Y.tree.getNodeById(a);
if(X!=null&&X.xtra!=null&&X.xtra.id!=null){var V=W.length;
while(-1<--V){W[V](X.xtra)
}}}}
}function K(V,W){if((V==null&&L.length==0)||typeof (W)!="function"){return 
}if(V==null){V=L[0].name
}if(B[V]==null){B[V]=[]
}B[V].push(W);
var U=L.length;
while(-1<--U){if(L[U].name==V){var X=L[U].tree.getSelNode();
if(X!=null&&X.xtra!=null){W(X.xtra)
}}}}function D(U,V){return function(Z){var X=nlsddSession.destData.xtra.id;
if(X!=null){var W=nlsddSession.srcData;
var Y=W.length;
while(-1<--Y){if(W[Y].xtra.id!=null){jQuery.ajax({url:AJS.Confluence.getContextPath()+"/plugins/builder/pagetree/move.action",data:{pageId:W[Y].xtra.id,parentId:X},dataType:"json",cache:false,success:function(a){if(a&&a.errorMessage){O(a.errorMessage)
}}})
}}V(Z)
}}
}function R(V,Z,Y){M=Y;
if(typeof (Z.iconpath)!="undefined"){T=Z.iconpath
}var X=L.length;
L[X]=Z;
var U=Z.tree=new NlsTree("pagetree"+X);
Z.children={};
Z.selectNode=V.id;
Z.treeDD=new NlsTreeDD("pagetree"+X);
Z.treeDD.onNodeDrop=D(X,Z.treeDD.onNodeDrop);
N(U,Z);
U.treeOnExpand=I(X);
U.treeOnClick=C(X);
var a=P(X,V.id);
V.treeId=X;
var W=U.add(a,0,V.title,(Z.openpage)?V.url:"",J(Z.iconStyle,V.type),true,false,V,(Z.titletip)?V.title:V.tooltip);
W.sortFunc=H[V.type];
U.add(a+"_loading",a,"loading...","",J(Z.iconStyle,"loading"));
U.setDrag(a,false,false);
U.setDrop(a,Z.allowdrag&&(V.type=="page"||V.type=="homepage"||V.type=="space")&&V.createPermission,false);
G(V.id,X,Z);
U.renderAttributes();
return U
}return{generateTree:R,addListener:K}
})()
};
