/*----------------------------------------------------|
  | dTree 2.05 | www.destroydrop.com/javascript/tree/ |
  |---------------------------------------------------|
  | Copyright (c) 2002-2003 Geir Landro               |
  |                                                   |
  | This script can be used freely as long as all     |
  | copyright messages are intact.                    |
  |                                                   |
  | Updated: 17.04.2003                               |
  |---------------------------------------------------|
  | Modified for Dokuwiki by                          |
  | Samuele Tognini <samuele@cli.di.unipi.it>         |
  | under GPL 2 license                               |
  | (http://www.gnu.org/licenses/gpl.html)            | 
  | Updated: 25.05.2007                               |
  |---------------------------------------------------|
  | indexmenu  | wiki.splitbrain.org/plugin:indexmenu |
  |--------------------------------------------------*/function Node(a,b,c,d,e,f,g,h,i){this.dokuid=a;this.id=b;this.pid=c;this.name=d;this.url=e;this.title=f||d;this.icon=g;this.iconOpen=h;this._io=i||false;this._is=false;this._ls=false;this._hc=false;this._ai=0;this._p=false;this._lv=0;this._ok=false;this._cp=false}function dTree(a,b){var c=indexmenu_findExt(b);this.config={useCookies:true,scroll:true,toc:true,max:1};this.icon={root:b+"base."+c,folder:b+"folder."+c,folderH:b+"folderh."+c,folderOpen:b+"folderopen."+c,folderHOpen:b+"folderhopen."+c,node:b+"page."+c,empty:b+"empty."+c,line:b+"line."+c,join:b+"join."+c,joinBottom:b+"joinbottom."+c,plus:b+"plus."+c,plusBottom:b+"plusbottom."+c,minus:b+"minus."+c,minusBottom:b+"minusbottom."+c,nlPlus:b+"nolines_plus."+c,nlMinus:b+"nolines_minus."+c};this.obj=a;this.aNodes=[];this.aIndent=[];this.root=new Node(false,-1);this.selectedNode=null;this.selectedFound=false;this.completed=false;this.scrllTmr=0;this.pageid=window.indexmenu_ID||""}dTree.prototype.add=function(a,b,c,d,e,f,g,h,i){this.aNodes[this.aNodes.length]=new Node(a,b,c,d,e,f,g,h,i)};dTree.prototype.openAll=function(){if(!this.getCookie("co"+this.obj)){this.oAll(true)}};dTree.prototype.toString=function(){var a="";if(this.config.scroll){a+='<div id="cdtree_'+this.obj+'" class="dtree" style="position:relative;overflow:hidden;width:100%;">'}a+='<div id="dtree_'+this.obj+'" class="dtree" style="overflow:';if(this.config.scroll){a+='visible;position:relative;width:100%"'}else{a+='hidden;"'}a+=">";if(this.config.toc){a+='<div id="t'+this.obj+'" style="display:none;"><a href="#"><img class="indexmenu_tocbullet" src="'+DOKU_BASE+'lib/plugins/indexmenu/images/toc_bullet.gif" /></a></div>';a+='<div id="toc_'+this.obj+'" style="display:none;"></div>'}if(document.getElementById){if(this.config.useCookies){this.selectedNode=this.getSelected()}a+=this.addNode(this.root)}else{a+="Browser not supported."}a+="</div>";if(this.config.scroll){a+='<div id="left_'+this.obj+'" class="indexmenu_arrow" style="display:none;" alt="Scroll back" onMouseOver="javascript:'+this.obj+".scroll('right',2);\" onMouseOut=\"javascript:"+this.obj+'.stopscroll()" onMouseDown="javascript:'+this.obj+".scroll('right',6);\" onMouseUp=\"javascript:"+this.obj+".scroll('right',2);\"></div>";a+="</div>"}this.completed=true;var b=document.getElementById("nojs_"+this.obj);if(b){b.style.display="none"}return a};dTree.prototype.addNode=function(a){var b="";var c;var n=a._ai;var l=a._lv+1;for(n;n<this.aNodes.length;n++){if(this.aNodes[n].pid==a.id){c=this.aNodes[n];c._p=a;c._ai=n;c._lv=l;this.setCS(c);if(c._hc&&!c._io&&this.config.useCookies){c._io=this.isOpen(c.id)}if(c.dokuid==this.pageid){c._cp=true}else{if(c.id==this.selectedNode&&!this.selectedFound){c._is=true;this.selectedNode=n;this.selectedFound=true}}b+=this.node(c,n);if(c._ls){break}}}return b};dTree.prototype.node=function(a,b){var h=false;var c="";if(this.config.toc||this.config.scroll){c+='onmouseover="';if(this.config.toc){c+=this.obj+".show_bullet('"+b+"');"}if(this.config.scroll){c+=this.obj+".scroll('left','"+b+"');"}c+='"'}if(a._lv>this.config.max){a._io=false;h=true}else{a._ok=true}var d='<div class="dTreeNode">'+this.indent(a,b);if(!a.icon){a.icon=(this.root.id==a.pid)?this.icon.root:((a._hc)?((!a.url)?this.icon.folder:this.icon.folderH):this.icon.node)}if(!a.iconOpen){a.iconOpen=(a._hc)?((!a.url)?this.icon.folderOpen:this.icon.folderHOpen):this.icon.node}if(this.root.id==a.pid){a.icon=this.icon.root;a.iconOpen=this.icon.root}d+='<img id="i'+this.obj+b+'" src="'+((a._io)?a.iconOpen:a.icon)+'" alt="" />';if(a.url){d+='<a id="s'+this.obj+b+'" class="'+((a._cp)?"navSel":((a._is)?"nodeSel":(a._hc)?"nodeFdUrl":"nodeUrl"));d+='" href="'+a.url+'" title="'+a.title+'"';d+=c;d+=' onclick="javascript: '+this.obj+".s("+b+');"';d+=">"}else{if(!a.url&&a._hc&&a.pid!=this.root.id){d+='<a id="s'+this.obj+b+'" href="javascript: '+this.obj+".o("+b+');" class="node"';d+=c;d+=">"}}d+=a.name;if(a.url||(!a.url&&a._hc)){d+="</a>"}d+="</div>";if(a._hc){d+='<div id="d'+this.obj+b+'" class="clip" style="display:'+((this.root.id==a.pid||a._io)?"block":"none")+';">';if(!h){d+=this.addNode(a)}d+="</div>"}this.aIndent.pop();return d};dTree.prototype.indent=function(a,b){var c="";if(this.root.id!=a.pid){for(var n=0;n<this.aIndent.length;n++){c+='<img src="'+((this.aIndent[n]==1)?this.icon.line:this.icon.empty)+'" alt="" />'}if(a._ls){this.aIndent.push(0)}else{this.aIndent.push(1)}if(a._hc){c+='<a href="javascript: '+this.obj+".o("+b+');"><img id="j'+this.obj+b+'" src="';c+=((a._io)?((a._ls)?this.icon.minusBottom:this.icon.minus):((a._ls)?this.icon.plusBottom:this.icon.plus));c+='" alt="" /></a>'}else{c+='<img src="'+((a._ls)?this.icon.joinBottom:this.icon.join)+'" alt="" />'}}return c};dTree.prototype.setCS=function(a){var b;for(var n=0;n<this.aNodes.length;n++){if(this.aNodes[n].pid==a.id){a._hc=true}if(this.aNodes[n].pid==a.pid){b=this.aNodes[n].id}}if(b==a.id){a._ls=true}};dTree.prototype.getSelected=function(){var a=this.getCookie("cs"+this.obj);return(a)?a:null};dTree.prototype.s=function(a){var b=this.aNodes[a];if(this.selectedNode!=a){var c=document.getElementById("s"+this.obj+a);if(!c){return}if(this.selectedNode||this.selectedNode===0){eOld=document.getElementById("s"+this.obj+this.selectedNode);eOld.className="node"}c.className="nodeSel";this.selectedNode=a;if(this.config.useCookies){this.setCookie("cs"+this.obj,b.id)}}};dTree.prototype.o=function(a){var b=this.aNodes[a];this.nodeStatus(!b._io,a,b._ls);b._io=!b._io;if(this.config.useCookies){this.updateCookie()}};dTree.prototype.oAll=function(a){for(var n=0;n<this.aNodes.length;n++){if(this.aNodes[n]._hc&&this.aNodes[n].pid!=this.root.id){this.nodeStatus(a,n,this.aNodes[n]._ls);this.aNodes[n]._io=a}}if(this.config.useCookies){this.updateCookie()}};dTree.prototype.openTo=function(a,b,c){if(!c){for(var n=0;n<this.aNodes.length;n++){if(this.aNodes[n].id==a){a=n;break}}}this.fill(this.aNodes[a].pid);var d=this.aNodes[a];if(d.pid==this.root.id||!d._p){return}d._io=true;d._is=b;if(this.completed&&d._hc){this.nodeStatus(true,d._ai,d._ls)}if(this.completed&&b){this.s(d._ai)}else{if(b){this._sn=d._ai}}this.openTo(d._p._ai,false,true)};dTree.prototype.getOpenTo=function(a){if(a===""){this.openAll()}else{if(!this.config.useCookies||!this.getCookie("co"+this.obj)){var b=a.split(",");for(var n=0;n<b.length;n++){this.openTo(b[n],false,true)}}}};dTree.prototype.nodeStatus=function(a,b,c){if(a&&!this.fill(b)){return}var d=document.getElementById("d"+this.obj+b);var e=document.getElementById("j"+this.obj+b);var f=document.getElementById("i"+this.obj+b);f.src=(a)?this.aNodes[b].iconOpen:this.aNodes[b].icon;e.src=((a)?((c)?this.icon.minusBottom:this.icon.minus):((c)?this.icon.plusBottom:this.icon.plus));d.style.display=(a)?"block":"none"};dTree.prototype.clearCookie=function(){var a=new Date();var b=new Date(a.getTime()-1000*60*60*24);this.setCookie("co"+this.obj,"cookieValue",b);this.setCookie("cs"+this.obj,"cookieValue",b)};dTree.prototype.setCookie=function(a,b,c,d,e,f){document.cookie=escape(a)+"="+escape(b)+(c?"; expires="+c.toGMTString():"")+";path=/"+(e?"; domain="+e:"")+(f?"; secure":"")};dTree.prototype.getCookie=function(a){var b="";var c=document.cookie.indexOf(escape(a)+"=");if(c!=-1){var d=c+(escape(a)+"=").length;var e=document.cookie.indexOf(";",d);if(e!=-1){b=unescape(document.cookie.substring(d,e))}else{b=unescape(document.cookie.substring(d))}}return(b)};dTree.prototype.updateCookie=function(){var a="";for(var n=0;n<this.aNodes.length;n++){if(this.aNodes[n]._io&&this.aNodes[n].pid!=this.root.id){if(a){a+="."}a+=this.aNodes[n].id}}this.setCookie("co"+this.obj,a)};dTree.prototype.isOpen=function(a){var b=this.getCookie("co"+this.obj).split(".");for(var n=0;n<b.length;n++){if(b[n]==a){return true}}return false};dTree.prototype.openCurNS=function(){var a;var b=this.pageid;for(var n=0;n<this.aNodes.length;n++){a=this.aNodes[n];if(a.dokuid==b){this.openTo(a.id,false,true);break}}};dTree.prototype.fill=function(a){if(a==-1||this.aNodes[a]._ok){return true}var b;var n=a;var c=[];var d;while(!this.aNodes[n]._ok){c[c.length]=n;n=this.aNodes[n].pid}for(var e=c.length-1;e>=0;e--){a=c[e];b=this.aNodes[a];d=document.getElementById("d"+this.obj+a);if(!d){return false}this.aIndent=[];n=b;while(n.pid>=0){if(n._ls){this.aIndent.unshift(0)}else{this.aIndent.unshift(1)}n=n._p}d.innerHTML=this.addNode(b);b._ok=true}return true};dTree.prototype.openCookies=function(){var a=this.getCookie("co"+this.obj).split(".");for(var n=0;n<a.length;n++){if(a[n]===""){break}var b=this.aNodes[a[n]];if(!b._ok){this.nodeStatus(true,a[n],b._ls);b._io=true}}};dTree.prototype.scroll=function(a,n){var w;var b=document.getElementById("dtree_"+this.obj);var c=parseInt(b.offsetLeft,0);this.stopscroll();if(a=="right"){this.scrollRight(c,n)}else{var d=document.getElementById("s"+this.obj+n);w=parseInt(b.parentNode.offsetWidth-d.offsetWidth-d.offsetLeft,0);if(this.config.toc){w=w-11}if(c<=w){return}this.scrollLeft(c,w);var e=document.getElementById("left_"+this.obj);if(e.style.display=="none"){w=parseInt(b.offsetHeight/3,0);var h=parseInt(w/50,0)*50;if(h<50){h=50}e.style.height=h+"px";e.style.top=w+"px";e.style.display="block"}}};dTree.prototype.scrollLeft=function(a,w){if(a<w){this.scrllTmr=0;return}var b=this;document.getElementById("dtree_"+b.obj).style.left=a+"px";this.scrllTmr=setTimeout(function(){b.scrollLeft(a-4,w)},20)};dTree.prototype.scrollRight=function(a,b){if(a>0){document.getElementById("left_"+this.obj).style.display="none";this.scrllTmr=0;return}var c=this;document.getElementById("dtree_"+c.obj).style.left=a+"px";this.scrllTmr=setTimeout(function(){c.scrollRight((a+b>0)?a+1:a+b,b)},10)};dTree.prototype.stopscroll=function(){clearTimeout(this.scrllTmr);this.scrllTmr=0};dTree.prototype.show_bullet=function(n){var a=document.getElementById("s"+this.obj+n);if(a.className=="node"){return}var b=document.getElementById("t"+this.obj);b.firstChild.href="javascript: indexmenu_ajax('req=toc&id="+this.aNodes[n].dokuid+"','picker_"+this.obj+"','"+b.id+"');";a.parentNode.appendChild(b);if(b.style.display=="none"){b.style.display="inline"}};if(!Array.prototype.push){Array.prototype.push=function array_push(){for(var i=0;i<arguments.length;i++){this[this.length]=arguments[i]}return this.length}}if(!Array.prototype.pop){Array.prototype.pop=function array_pop(){var a=this[this.length-1];this.length=Math.max(this.length-1,0);return a}}function indexmenu_findExt(a){var b="gif";var c=a.lastIndexOf(".");if(c>-1){c++;c=a.substring(c,a.length-1).toLowerCase();if((c=="png")||(c=="jpg")){b=c}}return b}
