var DOKU_BASE   = '/helpdesk/';var DOKU_TPL    = '/helpdesk/lib/tpl/default/';var DOKU_UHN    = 1;var DOKU_UHC    = 1;LANG = {"searchmedia":"Zoek naar bestanden","keepopen":"Houd scherm open bij selectie","hidedetails":"Verberg details","nosmblinks":"Linken naar Windows shares werkt alleen in Microsoft Internet Explorer.\nJe kan de link wel kopi\u00ebren en plakken.","linkwiz":"Linkwizard","linkto":"Link naar:","del_confirm":"Item(s) verwijderen?","mu_btn":"Meerdere files tegelijk uploaden","plugins":[]};
var toolbar = [{"type":"format","title":"Vette tekst","icon":"bold.png","key":"b","open":"**","close":"**"},{"type":"format","title":"Cursieve tekst","icon":"italic.png","key":"i","open":"\/\/","close":"\/\/"},{"type":"format","title":"Onderstreepte tekst","icon":"underline.png","key":"u","open":"__","close":"__"},{"type":"format","title":"Code tekst","icon":"mono.png","key":"c","open":"''","close":"''"},{"type":"format","title":"Doorgestreepte tekst","icon":"strike.png","key":"d","open":"<del>","close":"<\/del>"},{"type":"autohead","title":"Koptekst op zelfde niveau","icon":"hequal.png","key":"8","text":"Koptekst","mod":0},{"type":"autohead","title":"Lagere koptekst","icon":"hminus.png","key":"9","text":"Koptekst","mod":1},{"type":"autohead","title":"Hogere koptekst","icon":"hplus.png","key":"0","text":"Koptekst","mod":-1},{"type":"picker","title":"Kies koptekst","icon":"h.png","class":"pk_hl","list":[{"type":"format","title":"Niveau 1 kop","icon":"h1.png","key":"1","open":"====== ","close":" ======\\n"},{"type":"format","title":"Niveau 2 kop","icon":"h2.png","key":"2","open":"===== ","close":" =====\\n"},{"type":"format","title":"Niveau 3 kop","icon":"h3.png","key":"3","open":"==== ","close":" ====\\n"},{"type":"format","title":"Niveau 4 kop","icon":"h4.png","key":"4","open":"=== ","close":" ===\\n"},{"type":"format","title":"Niveau 5 kop","icon":"h5.png","key":"5","open":"== ","close":" ==\\n"}]},{"type":"linkwiz","title":"Interne link","icon":"link.png","key":"l","open":"[[","close":"]]"},{"type":"format","title":"Externe link","icon":"linkextern.png","open":"[[","close":"]]","sample":"http:\/\/example.com|Externe link"},{"type":"formatln","title":"Geordende lijst","icon":"ol.png","open":"  - ","close":"","key":"-"},{"type":"formatln","title":"Ongeordende lijst","icon":"ul.png","open":"  * ","close":"","key":"."},{"type":"insert","title":"Horizontale lijn","icon":"hr.png","insert":"\\n----\\n"},{"type":"mediapopup","title":"Voeg plaatjes en andere bestanden toe","icon":"image.png","url":"lib\/exe\/mediamanager.php?ns=","name":"mediaselect","options":"width=750,height=500,left=20,top=20,scrollbars=yes,resizable=yes"},{"type":"picker","title":"Smileys","icon":"smiley.png","list":{"8-)":"icon_cool.gif","8-O":"icon_eek.gif","8-o":"icon_eek.gif",":-(":"icon_sad.gif",":-)":"icon_smile.gif","=)":"icon_smile2.gif",":-\/":"icon_doubt.gif",":-\\":"icon_doubt2.gif",":-?":"icon_confused.gif",":-D":"icon_biggrin.gif",":-P":"icon_razz.gif",":-o":"icon_surprised.gif",":-O":"icon_surprised.gif",":-x":"icon_silenced.gif",":-X":"icon_silenced.gif",":-|":"icon_neutral.gif",";-)":"icon_wink.gif","^_^":"icon_fun.gif",":?:":"icon_question.gif",":!:":"icon_exclaim.gif","LOL":"icon_lol.gif","FIXME":"fixme.gif","DELETEME":"delete.gif"},"icobase":"smileys"},{"type":"picker","title":"Speciale tekens","icon":"chars.png","list":["\u00c0","\u00e0","\u00c1","\u00e1","\u00c2","\u00e2","\u00c3","\u00e3","\u00c4","\u00e4","\u01cd","\u01ce","\u0102","\u0103","\u00c5","\u00e5","\u0100","\u0101","\u0104","\u0105","\u00c6","\u00e6","\u0106","\u0107","\u00c7","\u00e7","\u010c","\u010d","\u0108","\u0109","\u010a","\u010b","\u00d0","\u0111","\u00f0","\u010e","\u010f","\u00c8","\u00e8","\u00c9","\u00e9","\u00ca","\u00ea","\u00cb","\u00eb","\u011a","\u011b","\u0112","\u0113","\u0116","\u0117","\u0118","\u0119","\u0122","\u0123","\u011c","\u011d","\u011e","\u011f","\u0120","\u0121","\u0124","\u0125","\u00cc","\u00ec","\u00cd","\u00ed","\u00ce","\u00ee","\u00cf","\u00ef","\u01cf","\u01d0","\u012a","\u012b","\u0130","\u0131","\u012e","\u012f","\u0134","\u0135","\u0136","\u0137","\u0139","\u013a","\u013b","\u013c","\u013d","\u013e","\u0141","\u0142","\u013f","\u0140","\u0143","\u0144","\u00d1","\u00f1","\u0145","\u0146","\u0147","\u0148","\u00d2","\u00f2","\u00d3","\u00f3","\u00d4","\u00f4","\u00d5","\u00f5","\u00d6","\u00f6","\u01d1","\u01d2","\u014c","\u014d","\u0150","\u0151","\u0152","\u0153","\u00d8","\u00f8","\u0154","\u0155","\u0156","\u0157","\u0158","\u0159","\u015a","\u015b","\u015e","\u015f","\u0160","\u0161","\u015c","\u015d","\u0162","\u0163","\u0164","\u0165","\u00d9","\u00f9","\u00da","\u00fa","\u00db","\u00fb","\u00dc","\u00fc","\u01d3","\u01d4","\u016c","\u016d","\u016a","\u016b","\u016e","\u016f","\u01d6","\u01d8","\u01da","\u01dc","\u0172","\u0173","\u0170","\u0171","\u0174","\u0175","\u00dd","\u00fd","\u0178","\u00ff","\u0176","\u0177","\u0179","\u017a","\u017d","\u017e","\u017b","\u017c","\u00de","\u00fe","\u00df","\u0126","\u0127","\u00bf","\u00a1","\u00a2","\u00a3","\u00a4","\u00a5","\u20ac","\u00a6","\u00a7","\u00aa","\u00ac","\u00af","\u00b0","\u00b1","\u00f7","\u2030","\u00bc","\u00bd","\u00be","\u00b9","\u00b2","\u00b3","\u00b5","\u00b6","\u2020","\u2021","\u00b7","\u2022","\u00ba","\u2200","\u2202","\u2203","\u018f","\u0259","\u2205","\u2207","\u2208","\u2209","\u220b","\u220f","\u2211","\u203e","\u2212","\u2217","\u221a","\u221d","\u221e","\u2220","\u2227","\u2228","\u2229","\u222a","\u222b","\u2234","\u223c","\u2245","\u2248","\u2260","\u2261","\u2264","\u2265","\u2282","\u2283","\u2284","\u2286","\u2287","\u2295","\u2297","\u22a5","\u22c5","\u25ca","\u2118","\u2111","\u211c","\u2135","\u2660","\u2663","\u2665","\u2666","\u03b1","\u03b2","\u0393","\u03b3","\u0394","\u03b4","\u03b5","\u03b6","\u03b7","\u0398","\u03b8","\u03b9","\u03ba","\u039b","\u03bb","\u03bc","\u039e","\u03be","\u03a0","\u03c0","\u03c1","\u03a3","\u03c3","\u03a4","\u03c4","\u03c5","\u03a6","\u03c6","\u03c7","\u03a8","\u03c8","\u03a9","\u03c9","\u2605","\u2606","\u260e","\u261a","\u261b","\u261c","\u261d","\u261e","\u261f","\u2639","\u263a","\u2714","\u2718","\u00d7","\u201e","\u201c","\u201d","\u201a","\u2018","\u2019","\u00ab","\u00bb","\u2039","\u203a","\u2014","\u2013","\u2026","\u2190","\u2191","\u2192","\u2193","\u2194","\u21d0","\u21d1","\u21d2","\u21d3","\u21d4","\u00a9","\u2122","\u00ae","\u2032","\u2033","[","]","{","}","~","(",")","%","\u00a7","$","#","|","@"]},{"type":"signature","title":"Handtekening invoegen","icon":"sig.png","key":"y"},{"type":"format","title":"","icon":"..\/..\/plugins\/imageflow\/images\/namespace_picker.png","open":"<imageflow ","sample":":namespace:goes:here:","close":"><\/imageflow>"}];


/* XXXXXXXXXX begin of lib/scripts/helpers.js XXXXXXXXXX */

/**
 * Differrent helper functions
 *
 * @author Ilya Lebedev <ilya@lebedev.net>
 * @license LGPL
 */
//-----------------------------------------------------------------------------
//  Variable/property checks
//-----------------------------------------------------------------------------
/**
 *  Checks if property is undefined
 *
 *  @param {Object} prop value to check
 *  @return {Boolean} true if matched
 *  @scope public
 */
function isUndefined (prop /* :Object */) /* :Boolean */ {
  return (typeof prop == 'undefined');
}
/**
 *  Checks if property is function
 *
 *  @param {Object} prop value to check
 *  @return {Boolean} true if matched
 *  @scope public
 */
function isFunction (prop /* :Object */) /* :Boolean */ {
  return (typeof prop == 'function');
}
/**
 *  Checks if property is string
 *
 *  @param {Object} prop value to check
 *  @return {Boolean} true if matched
 *  @scope public
 */
function isString (prop /* :Object */) /* :Boolean */ {
  return (typeof prop == 'string');
}
/**
 *  Checks if property is number
 *
 *  @param {Object} prop value to check
 *  @return {Boolean} true if matched
 *  @scope public
 */
function isNumber (prop /* :Object */) /* :Boolean */ {
  return (typeof prop == 'number');
}
/**
 *  Checks if property is the calculable number
 *
 *  @param {Object} prop value to check
 *  @return {Boolean} true if matched
 *  @scope public
 */
function isNumeric (prop /* :Object */) /* :Boolean */ {
  return isNumber(prop)&&!isNaN(prop)&&isFinite(prop);
}
/**
 *  Checks if property is array
 *
 *  @param {Object} prop value to check
 *  @return {Boolean} true if matched
 *  @scope public
 */
function isArray (prop /* :Object */) /* :Boolean */ {
  return (prop instanceof Array);
}
/**
 *  Checks if property is regexp
 *
 *  @param {Object} prop value to check
 *  @return {Boolean} true if matched
 *  @scope public
 */
function isRegExp (prop /* :Object */) /* :Boolean */ {
  return (prop instanceof RegExp);
}
/**
 *  Checks if property is a boolean value
 *
 *  @param {Object} prop value to check
 *  @return {Boolean} true if matched
 *  @scope public
 */
function isBoolean (prop /* :Object */) /* :Boolean */ {
  return ('boolean' == typeof prop);
}
/**
 *  Checks if property is a scalar value (value that could be used as the hash key)
 *
 *  @param {Object} prop value to check
 *  @return {Boolean} true if matched
 *  @scope public
 */
function isScalar (prop /* :Object */) /* :Boolean */ {
  return isNumeric(prop)||isString(prop);
}
/**
 *  Checks if property is empty
 *
 *  @param {Object} prop value to check
 *  @return {Boolean} true if matched
 *  @scope public
 */
function isEmpty (prop /* :Object */) /* :Boolean */ {
  if (isBoolean(prop)) return false;
  if (isRegExp(prop) && new RegExp("").toString() == prop.toString()) return true;
  if (isString(prop) || isNumber(prop)) return !prop;
  if (Boolean(prop)&&false != prop) {
    for (var i in prop) if(prop.hasOwnProperty(i)) return false
  }
  return true;
}

/**
 *  Checks if property is derived from prototype, applies method if it is not exists
 *
 *  @param string property name
 *  @return bool true if prototyped
 *  @access public
 */
if ('undefined' == typeof Object.hasOwnProperty) {
  Object.prototype.hasOwnProperty = function (prop) {
    return !('undefined' == typeof this[prop] || this.constructor && this.constructor.prototype[prop] && this[prop] === this.constructor.prototype[prop]);
  }
}

/**
 * Very simplistic Flash plugin check, probably works for Flash 8 and higher only
 */
function hasFlash(version){
    var ver = 0;
    try{
        if(navigator.plugins != null && navigator.plugins.length > 0){
           ver = navigator.plugins["Shockwave Flash"].description.split(' ')[2].split('.')[0];
        }else{
           var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
           ver = axo.GetVariable("$version").split(' ')[1].split(',')[0];
        }
    }catch(e){ }

    if(ver >= version) return true;
    return false;
}


/* XXXXXXXXXX end of lib/scripts/helpers.js XXXXXXXXXX */



/* XXXXXXXXXX begin of lib/scripts/events.js XXXXXXXXXX */

// written by Dean Edwards, 2005
// with input from Tino Zijdel

// http://dean.edwards.name/weblog/2005/10/add-event/

function addEvent(element, type, handler) {
    // assign each event handler a unique ID
    if (!handler.$$guid) handler.$$guid = addEvent.guid++;
    // create a hash table of event types for the element
    if (!element.events) element.events = {};
    // create a hash table of event handlers for each element/event pair
    var handlers = element.events[type];
    if (!handlers) {
        handlers = element.events[type] = {};
        // store the existing event handler (if there is one)
        if (element["on" + type]) {
            handlers[0] = element["on" + type];
        }
    }
    // store the event handler in the hash table
    handlers[handler.$$guid] = handler;
    // assign a global event handler to do all the work
    element["on" + type] = handleEvent;
};
// a counter used to create unique IDs
addEvent.guid = 1;

function removeEvent(element, type, handler) {
    // delete the event handler from the hash table
    if (element.events && element.events[type]) {
        delete element.events[type][handler.$$guid];
    }
};

function handleEvent(event) {
    var returnValue = true;
    // grab the event object (IE uses a global event object)
    event = event || fixEvent(window.event);
    // get a reference to the hash table of event handlers
    var handlers = this.events[event.type];
    // execute each event handler
    for (var i in handlers) {
        if (!handlers.hasOwnProperty(i)) continue;
        this.$$handleEvent = handlers[i];
        if (this.$$handleEvent(event) === false) {
            returnValue = false;
        }
    }
    return returnValue;
};

function fixEvent(event) {
    // add W3C standard event methods
    event.preventDefault = fixEvent.preventDefault;
    event.stopPropagation = fixEvent.stopPropagation;
    // fix target
    event.target = event.srcElement;
    return event;
};
fixEvent.preventDefault = function() {
    this.returnValue = false;
};
fixEvent.stopPropagation = function() {
    this.cancelBubble = true;
};


/**
 * Pseudo event handler to be fired after the DOM was parsed or
 * on window load at last.
 *
 * @author based upon some code by Dean Edwards
 * @author Dean Edwards
 * @link   http://dean.edwards.name/weblog/2006/06/again/
 */
window.fireoninit = function() {
  // quit if this function has already been called
  if (arguments.callee.done) return;
  // flag this function so we don't do the same thing twice
  arguments.callee.done = true;
  // kill the timer
  if (_timer) {
     clearInterval(_timer);
     _timer = null;
  }

  if (typeof window.oninit == 'function') {
        window.oninit();
  }
};

/**
 * Run the fireoninit function as soon as possible after
 * the DOM was loaded, using different methods for different
 * Browsers
 *
 * @author Dean Edwards
 * @link   http://dean.edwards.name/weblog/2006/06/again/
 */
  // for Mozilla
  if (document.addEventListener) {
    document.addEventListener("DOMContentLoaded", window.fireoninit, null);
  }

  // for Internet Explorer (using conditional comments)
  /*@cc_on @*/
  /*@if (@_win32)
    document.write("<scr" + "ipt id=\"__ie_init\" defer=\"true\" src=\"//:\"><\/script>");
    var script = document.getElementById("__ie_init");
    script.onreadystatechange = function() {
        if (this.readyState == "complete") {
            window.fireoninit(); // call the onload handler
        }
    };
  /*@end @*/

  // for Safari
  if (/WebKit/i.test(navigator.userAgent)) { // sniff
    var _timer = setInterval(function() {
        if (/loaded|complete/.test(document.readyState)) {
            window.fireoninit(); // call the onload handler
        }
    }, 10);
  }

  // for other browsers
  window.onload = window.fireoninit;


/**
 * This is a pseudo Event that will be fired by the fireoninit
 * function above.
 *
 * Use addInitEvent to bind to this event!
 *
 * @author Andreas Gohr <andi@splitbrain.org>
 * @see fireoninit()
 */
window.oninit = function(){};

/**
 * Bind a function to the window.init pseudo event
 *
 * @author Simon Willison
 * @see http://simon.incutio.com/archive/2004/05/26/addLoadEvent
 */
function addInitEvent(func) {
  var oldoninit = window.oninit;
  if (typeof window.oninit != 'function') {
    window.oninit = func;
  } else {
    window.oninit = function() {
      oldoninit();
      func();
    };
  }
}

/**
 * Bind variables to a function call creating a closure
 *
 * Use this to circumvent variable scope problems when creating closures
 * inside a loop
 *
 * @author  Adrian Lang <lang@cosmocode.de>
 * @link    http://www.cosmocode.de/en/blog/gohr/2009-10/15-javascript-fixing-the-closure-scope-in-loops
 * @param   functionref fnc - the function to be called
 * @param   mixed - any arguments to be passed to the function
 * @returns functionref
 */
function bind (fnc) {
    var args = Array.prototype.slice.call(arguments, 1);
    return function() {
        return fnc.apply(this, args);
    }
}


/* XXXXXXXXXX end of lib/scripts/events.js XXXXXXXXXX */



/* XXXXXXXXXX begin of lib/scripts/cookie.js XXXXXXXXXX */

/**
 * Handles the cookie used by several JavaScript functions
 *
 * Only a single cookie is written and read. You may only save
 * sime name-value pairs - no complex types!
 *
 * You should only use the getValue and setValue methods
 *
 * @author Andreas Gohr <andi@splitbrain.org>
 */
DokuCookie = {
    data: Array(),
    name: 'DOKU_PREFS',

    /**
     * Save a value to the cookie
     *
     * @author Andreas Gohr <andi@splitbrain.org>
     */
    setValue: function(key,val){
        DokuCookie.init();
        DokuCookie.data[key] = val;

        // prepare expire date
        var now = new Date();
        DokuCookie.fixDate(now);
        now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000); //expire in a year

        //save the whole data array
        var text = '';
        for(var key in DokuCookie.data){
            if (!DokuCookie.data.hasOwnProperty(key)) continue;
            text += '#'+escape(key)+'#'+DokuCookie.data[key];
        }
        DokuCookie.setCookie(DokuCookie.name,text.substr(1),now,DOKU_BASE);
    },

    /**
     * Get a Value from the Cookie
     *
     * @author Andreas Gohr <andi@splitbrain.org>
     */
    getValue: function(key){
        DokuCookie.init();
        return DokuCookie.data[key];
    },

    /**
     * Loads the current set cookie
     *
     * @author Andreas Gohr <andi@splitbrain.org>
     */
    init: function(){
        if(DokuCookie.data.length) return;
        var text  = DokuCookie.getCookie(DokuCookie.name);
        if(text){
            var parts = text.split('#');
            for(var i=0; i<parts.length; i+=2){
                DokuCookie.data[unescape(parts[i])] = unescape(parts[i+1]);
            }
        }
    },

    /**
     * This sets a cookie by JavaScript
     *
     * @link http://www.webreference.com/js/column8/functions.html
     */
    setCookie: function(name, value, expires, path, domain, secure) {
        var curCookie = name + "=" + escape(value) +
            ((expires) ? "; expires=" + expires.toGMTString() : "") +
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            ((secure) ? "; secure" : "");
        document.cookie = curCookie;
    },

    /**
     * This reads a cookie by JavaScript
     *
     * @link http://www.webreference.com/js/column8/functions.html
     */
    getCookie: function(name) {
        var dc = document.cookie;
        var prefix = name + "=";
        var begin = dc.indexOf("; " + prefix);
        if (begin == -1) {
            begin = dc.indexOf(prefix);
            if (begin !== 0){ return null; }
        } else {
            begin += 2;
        }
        var end = document.cookie.indexOf(";", begin);
        if (end == -1){
            end = dc.length;
        }
        return unescape(dc.substring(begin + prefix.length, end));
    },

    /**
     * This is needed for the cookie functions
     *
     * @link http://www.webreference.com/js/column8/functions.html
     */
    fixDate: function(date) {
        var base = new Date(0);
        var skew = base.getTime();
        if (skew > 0){
            date.setTime(date.getTime() - skew);
        }
    }
};


/* XXXXXXXXXX end of lib/scripts/cookie.js XXXXXXXXXX */



/* XXXXXXXXXX begin of lib/scripts/script.js XXXXXXXXXX */

/**
 * Some of these scripts were taken from wikipedia.org and were modified for DokuWiki
 */

/**
 * Some browser detection
 */
var clientPC  = navigator.userAgent.toLowerCase(); // Get client info
var is_macos  = navigator.appVersion.indexOf('Mac') != -1;
var is_gecko  = ((clientPC.indexOf('gecko')!=-1) && (clientPC.indexOf('spoofer')==-1) &&
                (clientPC.indexOf('khtml') == -1) && (clientPC.indexOf('netscape/7.0')==-1));
var is_safari = ((clientPC.indexOf('AppleWebKit')!=-1) && (clientPC.indexOf('spoofer')==-1));
var is_khtml  = (navigator.vendor == 'KDE' || ( document.childNodes && !document.all && !navigator.taintEnabled ));
if (clientPC.indexOf('opera')!=-1) {
    var is_opera = true;
    var is_opera_preseven = (window.opera && !document.childNodes);
    var is_opera_seven = (window.opera && document.childNodes);
}

/**
 * Handy shortcut to document.getElementById
 *
 * This function was taken from the prototype library
 *
 * @link http://prototype.conio.net/
 */
function $() {
  var elements = new Array();

  for (var i = 0; i < arguments.length; i++) {
    var element = arguments[i];
    if (typeof element == 'string')
      element = document.getElementById(element);

    if (arguments.length == 1)
      return element;

    elements.push(element);
  }

  return elements;
}

/**
 * Simple function to check if a global var is defined
 *
 * @author Kae Verens
 * @link http://verens.com/archives/2005/07/25/isset-for-javascript/#comment-2835
 */
function isset(varname){
  return(typeof(window[varname])!='undefined');
}

/**
 * Select elements by their class name
 *
 * @author Dustin Diaz <dustin [at] dustindiaz [dot] com>
 * @link   http://www.dustindiaz.com/getelementsbyclass/
 */
function getElementsByClass(searchClass,node,tag) {
    var classElements = new Array();
    if ( node == null )
        node = document;
    if ( tag == null )
        tag = '*';
    var els = node.getElementsByTagName(tag);
    var elsLen = els.length;
    var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
    for (var i = 0, j = 0; i < elsLen; i++) {
        if ( pattern.test(els[i].className) ) {
            classElements[j] = els[i];
            j++;
        }
    }
    return classElements;
}

/**
 * Get the X offset of the top left corner of the given object
 *
 * @link http://www.quirksmode.org/index.html?/js/findpos.html
 */
function findPosX(object){
  var curleft = 0;
  var obj = $(object);
  if (obj.offsetParent){
    while (obj.offsetParent){
      curleft += obj.offsetLeft;
      obj = obj.offsetParent;
    }
  }
  else if (obj.x){
    curleft += obj.x;
  }
  return curleft;
} //end findPosX function

/**
 * Get the Y offset of the top left corner of the given object
 *
 * @link http://www.quirksmode.org/index.html?/js/findpos.html
 */
function findPosY(object){
  var curtop = 0;
  var obj = $(object);
  if (obj.offsetParent){
    while (obj.offsetParent){
      curtop += obj.offsetTop;
      obj = obj.offsetParent;
    }
  }
  else if (obj.y){
    curtop += obj.y;
  }
  return curtop;
} //end findPosY function

/**
 * Escape special chars in JavaScript
 *
 * @author Andreas Gohr <andi@splitbrain.org>
 */
function jsEscape(text){
    var re=new RegExp("\\\\","g");
    text=text.replace(re,"\\\\");
    re=new RegExp("'","g");
    text=text.replace(re,"\\'");
    re=new RegExp('"',"g");
    text=text.replace(re,'&quot;');
    re=new RegExp("\\\\\\\\n","g");
    text=text.replace(re,"\\n");
    return text;
}

/**
 * This function escapes some special chars
 * @deprecated by above function
 */
function escapeQuotes(text) {
  var re=new RegExp("'","g");
  text=text.replace(re,"\\'");
  re=new RegExp('"',"g");
  text=text.replace(re,'&quot;');
  re=new RegExp("\\n","g");
  text=text.replace(re,"\\n");
  return text;
}

/**
 * Adds a node as the first childenode to the given parent
 *
 * @see appendChild()
 */
function prependChild(parent,element) {
    if(!parent.firstChild){
        parent.appendChild(element);
    }else{
        parent.insertBefore(element,parent.firstChild);
    }
}

/**
 * Prints a animated gif to show the search is performed
 *
 * Because we need to modify the DOM here before the document is loaded
 * and parsed completely we have to rely on document.write()
 *
 * @author Andreas Gohr <andi@splitbrain.org>
 */
function showLoadBar(){

  document.write('<img src="'+DOKU_BASE+'lib/images/loading.gif" '+
                 'width="150" height="12" alt="..." />');

  /* this does not work reliable in IE
  obj = $(id);

  if(obj){
    obj.innerHTML = '<img src="'+DOKU_BASE+'lib/images/loading.gif" '+
                    'width="150" height="12" alt="..." />';
    obj.style.display="block";
  }
  */
}

/**
 * Disables the animated gif to show the search is done
 *
 * @author Andreas Gohr <andi@splitbrain.org>
 */
function hideLoadBar(id){
  obj = $(id);
  if(obj) obj.style.display="none";
}

/**
 * Adds the toggle switch to the TOC
 */
function addTocToggle() {
    if(!document.getElementById) return;
    var header = $('toc__header');
    if(!header) return;
    var toc = $('toc__inside');

    var obj          = document.createElement('span');
    obj.id           = 'toc__toggle';
    obj.style.cursor = 'pointer';
    if (toc && toc.style.display == 'none') {
        obj.innerHTML    = '<span>+</span>';
        obj.className    = 'toc_open';
    } else {
        obj.innerHTML    = '<span>&minus;</span>';
        obj.className    = 'toc_close';
    }

    prependChild(header,obj);
    obj.parentNode.onclick = toggleToc;
    try {
       obj.parentNode.style.cursor = 'pointer';
       obj.parentNode.style.cursor = 'hand';
    }catch(e){}
}

/**
 * This toggles the visibility of the Table of Contents
 */
function toggleToc() {
  var toc = $('toc__inside');
  var obj = $('toc__toggle');
  if(toc.style.display == 'none') {
    toc.style.display   = '';
    obj.innerHTML       = '<span>&minus;</span>';
    obj.className       = 'toc_close';
  } else {
    toc.style.display   = 'none';
    obj.innerHTML       = '<span>+</span>';
    obj.className       = 'toc_open';
  }
}

/**
 * Display an insitu footnote popup
 *
 * @author Andreas Gohr <andi@splitbrain.org>
 * @author Chris Smith <chris@jalakai.co.uk>
 */
function footnote(e){
    var obj = e.target;
    var id = obj.id.substr(5);

    // get or create the footnote popup div
    var fndiv = $('insitu__fn');
    if(!fndiv){
        fndiv = document.createElement('div');
        fndiv.id        = 'insitu__fn';
        fndiv.className = 'insitu-footnote JSpopup dokuwiki';

        // autoclose on mouseout - ignoring bubbled up events
        addEvent(fndiv,'mouseout',function(e){
            if(e.target != fndiv){
                e.stopPropagation();
                return;
            }
            // check if the element was really left
            if(e.pageX){        // Mozilla
                var bx1 = findPosX(fndiv);
                var bx2 = bx1 + fndiv.offsetWidth;
                var by1 = findPosY(fndiv);
                var by2 = by1 + fndiv.offsetHeight;
                var x = e.pageX;
                var y = e.pageY;
                if(x > bx1 && x < bx2 && y > by1 && y < by2){
                    // we're still inside boundaries
                    e.stopPropagation();
                    return;
                }
            }else{              // IE
                if(e.offsetX > 0 && e.offsetX < fndiv.offsetWidth-1 &&
                   e.offsetY > 0 && e.offsetY < fndiv.offsetHeight-1){
                    // we're still inside boundaries
                    e.stopPropagation();
                    return;
                }
            }
            // okay, hide it
            fndiv.style.display='none';
        });
        document.body.appendChild(fndiv);
    }

    // locate the footnote anchor element
    var a = $( "fn__"+id );
    if (!a){ return; }

    // anchor parent is the footnote container, get its innerHTML
    var content = new String (a.parentNode.parentNode.innerHTML);

    // strip the leading content anchors and their comma separators
    content = content.replace(/<sup>.*<\/sup>/gi, '');
    content = content.replace(/^\s+(,\s+)+/,'');

    // prefix ids on any elements with "insitu__" to ensure they remain unique
    content = content.replace(/\bid=\"(.*?)\"/gi,'id="insitu__$1');

    // now put the content into the wrapper
    fndiv.innerHTML = content;

    // position the div and make it visible
    var x; var y;
    if(e.pageX){        // Mozilla
        x = e.pageX;
        y = e.pageY;
    }else{              // IE
        x = e.offsetX;
        y = e.offsetY;
    }
    fndiv.style.position = 'absolute';
    fndiv.style.left = (x+2)+'px';
    fndiv.style.top  = (y+2)+'px';
    fndiv.style.display = '';
}

/**
 * Add the event handlers to footnotes
 *
 * @author Andreas Gohr <andi@splitbrain.org>
 */
addInitEvent(function(){
    var elems = getElementsByClass('fn_top',null,'a');
    for(var i=0; i<elems.length; i++){
        addEvent(elems[i],'mouseover',function(e){footnote(e);});
    }
});

/**
 * Add the edit window size controls
 */
function initSizeCtl(ctlid,edid){
    if(!document.getElementById){ return; }

    var ctl      = $(ctlid);
    var textarea = $(edid);
    if(!ctl || !textarea) return;

    var hgt = DokuCookie.getValue('sizeCtl');
    if(hgt){
      textarea.style.height = hgt;
    }else{
      textarea.style.height = '300px';
    }

    var wrp = DokuCookie.getValue('wrapCtl');
    if(wrp){
      setWrap(textarea, wrp);
    } // else use default value

    var l = document.createElement('img');
    var s = document.createElement('img');
    var w = document.createElement('img');
    l.src = DOKU_BASE+'lib/images/larger.gif';
    s.src = DOKU_BASE+'lib/images/smaller.gif';
    w.src = DOKU_BASE+'lib/images/wrap.gif';
    addEvent(l,'click',function(){sizeCtl(edid,100);});
    addEvent(s,'click',function(){sizeCtl(edid,-100);});
    addEvent(w,'click',function(){toggleWrap(edid);});
    ctl.appendChild(l);
    ctl.appendChild(s);
    ctl.appendChild(w);
}

/**
 * This sets the vertical size of the editbox
 */
function sizeCtl(edid,val){
  var textarea = $(edid);
  var height = parseInt(textarea.style.height.substr(0,textarea.style.height.length-2));
  height += val;
  textarea.style.height = height+'px';

  DokuCookie.setValue('sizeCtl',textarea.style.height);
}

/**
 * Toggle the wrapping mode of a textarea
 */
function toggleWrap(edid){
    var textarea = $(edid);
    var wrap = textarea.getAttribute('wrap');
    if(wrap && wrap.toLowerCase() == 'off'){
        setWrap(textarea, 'soft');
    }else{
        setWrap(textarea, 'off');
    }

    DokuCookie.setValue('wrapCtl',textarea.getAttribute('wrap'));
}

/**
 * Set the wrapping mode of a textarea
 *
 * @author Fluffy Convict <fluffyconvict@hotmail.com>
 * @author <shutdown@flashmail.com>
 * @link   http://news.hping.org/comp.lang.javascript.archive/12265.html
 * @link   https://bugzilla.mozilla.org/show_bug.cgi?id=41464
 */
function setWrap(textarea, wrapAttrValue){
    textarea.setAttribute('wrap', wrapAttrValue);

    // Fix display for mozilla
    var parNod = textarea.parentNode;
    var nxtSib = textarea.nextSibling;
    parNod.removeChild(textarea);
    parNod.insertBefore(textarea, nxtSib);
}

/**
 * Handler to close all open Popups
 */
function closePopups(){
  if(!document.getElementById){ return; }

  var divs = document.getElementsByTagName('div');
  for(var i=0; i < divs.length; i++){
    if(divs[i].className.indexOf('JSpopup') != -1){
            divs[i].style.display = 'none';
    }
  }
}

/**
 * Looks for an element with the ID scroll__here at scrolls to it
 */
function scrollToMarker(){
    var obj = $('scroll__here');
    if(obj) obj.scrollIntoView();
}

/**
 * Looks for an element with the ID focus__this at sets focus to it
 */
function focusMarker(){
    var obj = $('focus__this');
    if(obj) obj.focus();
}

/**
 * Remove messages
 */
function cleanMsgArea(){
    var elems = getElementsByClass('(success|info|error)',document,'div');
    if(elems){
        for(var i=0; i<elems.length; i++){
            elems[i].style.display = 'none';
        }
    }
}

/**
 * disable multiple revisions checkboxes if two are checked
 *
 * @author Anika Henke <anika@selfthinker.org>
 */
addInitEvent(function(){
    var revForm = $('page__revisions');
    if (!revForm) return;
    var elems = revForm.elements;
    var countTicks = 0;
    for (var i=0; i<elems.length; i++) {
        var input1 = elems[i];
        if (input1.type=='checkbox') {
            addEvent(input1,'click',function(e){
                if (this.checked) countTicks++;
                else countTicks--;
                for (var j=0; j<elems.length; j++) {
                    var input2 = elems[j];
                    if (countTicks >= 2) input2.disabled = (input2.type=='checkbox' && !input2.checked);
                    else input2.disabled = (input2.type!='checkbox');
                }
            });
            input1.checked = false; // chrome reselects on back button which messes up the logic
        } else if(input1.type=='submit'){
            input1.disabled = true;
        }
    }
});

/**
 * Add the event handler to the actiondropdown
 *
 * @author Andreas Gohr <andi@splitbrain.org>
 */
addInitEvent(function(){
    var selector = $('action__selector');
    if(!selector) return;

    addEvent(selector,'change',function(e){
        this.form.submit();
    });

    $('action__selectorbtn').style.display = 'none';
});

/**
 * Display error for Windows Shares on browsers other than IE
 *
 * @author Michael Klier <chi@chimeric.de>
 */
function checkWindowsShares() {
    if(!LANG['nosmblinks']) return true;
    var elems = getElementsByClass('windows',document,'a');
    if(elems){
        for(var i=0; i<elems.length; i++){
            var share = elems[i];
            addEvent(share,'click',function(){
                if(document.all == null) {
                    alert(LANG['nosmblinks']);
                }
            });
        }
    }
}

/**
 * Add the event handler for the Windows Shares check
 *
 * @author Michael Klier <chi@chimeric.de>
 */
addInitEvent(function(){
    checkWindowsShares();
});

/**
 * Highlight the section when hovering over the appropriate section edit button
 *
 * @author Andreas Gohr <andi@splitbrain.org>
 */
addInitEvent(function(){
    var break_classes = new RegExp('secedit|toc|page');
    var btns = getElementsByClass('btn_secedit',document,'form');
    for(var i=0; i<btns.length; i++){
        addEvent(btns[i],'mouseover',function(e){
            var tgt = e.target;
            if(tgt.form) tgt = tgt.form;
            tgt = tgt.parentNode.previousSibling;
            if(tgt.nodeName != "DIV") tgt = tgt.previousSibling;
            while(!break_classes.test(tgt.className)) {
                tgt.className += ' section_highlight';
                if (tgt.tagName == 'H1') break;
                tgt = (tgt.previousSibling != null) ? tgt.previousSibling : tgt.parentNode;
            }
        });

        addEvent(btns[i],'mouseout',function(e){
            var secs = getElementsByClass('section_highlight');
            for(var j=0; j<secs.length; j++){
                secs[j].className = secs[j].className.replace(/section_highlight/,'');
            }
            var secs = getElementsByClass('section_highlight');
        });
    }
});


/* XXXXXXXXXX end of lib/scripts/script.js XXXXXXXXXX */



/* XXXXXXXXXX begin of lib/scripts/tw-sack.js XXXXXXXXXX */

/* Simple AJAX Code-Kit (SACK) */
/* ©2005 Gregory Wild-Smith */
/* www.twilightuniverse.com */
/* Software licenced under a modified X11 licence, see documentation or authors website for more details */

function sack(file){
  this.AjaxFailedAlert = "Your browser does not support the enhanced functionality of this website, and therefore you will have an experience that differs from the intended one.\n";
  this.requestFile = file;
  this.method = "POST";
  this.URLString = "";
  this.encodeURIString = true;
  this.execute = false;

  this.onLoading = function() { };
  this.onLoaded = function() { };
  this.onInteractive = function() { };
  this.onCompletion = function() { };
  this.afterCompletion = function() { };

  this.createAJAX = function() {
    try {
      this.xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (err) {
        this.xmlhttp = null;
      }
    }
    if(!this.xmlhttp && typeof XMLHttpRequest != "undefined"){
      this.xmlhttp = new XMLHttpRequest();
    }
    if (!this.xmlhttp){
      this.failed = true;
    }
  };

  this.setVar = function(name, value){
    if (this.URLString.length < 3){
      this.URLString = name + "=" + value;
    } else {
      this.URLString += "&" + name + "=" + value;
    }
  };

  this.encVar = function(name, value){
    var varString = encodeURIComponent(name) + "=" + encodeURIComponent(value);
  return varString;
  };

  this.encodeURLString = function(string){
    varArray = string.split('&');
    for (i = 0; i < varArray.length; i++){
      urlVars = varArray[i].split('=');
      if (urlVars[0].indexOf('amp;') != -1){
        urlVars[0] = urlVars[0].substring(4);
      }
      varArray[i] = this.encVar(urlVars[0],urlVars[1]);
    }
  return varArray.join('&');
  };

  this.runResponse = function(){
    eval(this.response);
  };

  this.runAJAX = function(urlstring){
    this.responseStatus = new Array(2);
    if(this.failed && this.AjaxFailedAlert){
      alert(this.AjaxFailedAlert);
    } else {
      if (urlstring){
        if (this.URLString.length){
          this.URLString = this.URLString + "&" + urlstring;
        } else {
          this.URLString = urlstring;
        }
      }
      if (this.encodeURIString){
        var timeval = new Date().getTime();
        this.URLString = this.encodeURLString(this.URLString);
        this.setVar("rndval", timeval);
      }
      if (this.element) { this.elementObj = document.getElementById(this.element); }
      if (this.xmlhttp) {
        var self = this;
        if (this.method == "GET") {
          var totalurlstring = this.requestFile + "?" + this.URLString;
          this.xmlhttp.open(this.method, totalurlstring, true);
        } else {
          this.xmlhttp.open(this.method, this.requestFile, true);
        }
        if (this.method == "POST"){
          try {
             this.xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');
          } catch (e) {}
        }

        this.xmlhttp.onreadystatechange = function() {
          switch (self.xmlhttp.readyState){
            case 1:
              self.onLoading();
            break;
            case 2:
              self.onLoaded();
            break;
            case 3:
              self.onInteractive();
            break;
            case 4:
              self.response = self.xmlhttp.responseText;
              self.responseXML = self.xmlhttp.responseXML;
              self.responseStatus[0] = self.xmlhttp.status;
              self.responseStatus[1] = self.xmlhttp.statusText;
              self.onCompletion();
              if(self.execute){ self.runResponse(); }
              if (self.elementObj) {
                var elemNodeName = self.elementObj.nodeName;
                elemNodeName.toLowerCase();
                if (elemNodeName == "input" || elemNodeName == "select" || elemNodeName == "option" || elemNodeName == "textarea"){
                  self.elementObj.value = self.response;
                } else {
                  self.elementObj.innerHTML = self.response;
                }
              }
              self.afterCompletion();
              self.URLString = "";
            break;
          }
        };
        this.xmlhttp.send(this.URLString);
      }
    }
  };
this.createAJAX();
}


/* XXXXXXXXXX end of lib/scripts/tw-sack.js XXXXXXXXXX */



/* XXXXXXXXXX begin of lib/scripts/ajax.js XXXXXXXXXX */

/**
 * AJAX functions for the pagename quicksearch
 *
 * We're using a global object with self referencing methods
 * here to make callbacks work
 *
 * @license  GPL2 (http://www.gnu.org/licenses/gpl.html)
 * @author   Andreas Gohr <andi@splitbrain.org>
 */

//prepare class
function ajax_qsearch_class(){
  this.sack = null;
  this.inObj = null;
  this.outObj = null;
  this.timer = null;
}

//create global object and add functions
var ajax_qsearch = new ajax_qsearch_class();
ajax_qsearch.sack = new sack(DOKU_BASE + 'lib/exe/ajax.php');
ajax_qsearch.sack.AjaxFailedAlert = '';
ajax_qsearch.sack.encodeURIString = false;

ajax_qsearch.init = function(inID,outID){
  ajax_qsearch.inObj  = document.getElementById(inID);
  ajax_qsearch.outObj = document.getElementById(outID);

  // objects found?
  if(ajax_qsearch.inObj === null){ return; }
  if(ajax_qsearch.outObj === null){ return; }

  // attach eventhandler to search field
  addEvent(ajax_qsearch.inObj,'keyup',ajax_qsearch.call);

  // attach eventhandler to output field
  addEvent(ajax_qsearch.outObj,'click',function(){ ajax_qsearch.outObj.style.display='none'; });
};

ajax_qsearch.clear = function(){
  ajax_qsearch.outObj.style.display = 'none';
  ajax_qsearch.outObj.innerHTML = '';
  if(ajax_qsearch.timer !== null){
    window.clearTimeout(ajax_qsearch.timer);
    ajax_qsearch.timer = null;
  }
};

ajax_qsearch.exec = function(){
  ajax_qsearch.clear();
  var value = ajax_qsearch.inObj.value;
  if(value === ''){ return; }
  ajax_qsearch.sack.runAJAX('call=qsearch&q='+encodeURI(value));
};

ajax_qsearch.sack.onCompletion = function(){
  var data = ajax_qsearch.sack.response;
  if(data === ''){ return; }

  ajax_qsearch.outObj.innerHTML = data;
  ajax_qsearch.outObj.style.display = 'block';
};

ajax_qsearch.call = function(){
  ajax_qsearch.clear();
  ajax_qsearch.timer = window.setTimeout("ajax_qsearch.exec()",500);
};



/* XXXXXXXXXX end of lib/scripts/ajax.js XXXXXXXXXX */



/* XXXXXXXXXX begin of lib/scripts/index.js XXXXXXXXXX */

/**
 * Javascript for index view
 *
 * @author Andreas Gohr <andi@splitbrain.org>
 */

var index = {

     /**
     * Delay in ms before showing the throbber.
     * Used to skip the throbber for fast AJAX calls.
     */
    throbber_delay: 500,

    /**
     * Attach event handlers to all "folders" below the given element
     *
     * @author Andreas Gohr <andi@splitbrain.org>
     */
    treeattach: function(obj){
        if(!obj) return;

        var items = getElementsByClass('idx_dir',obj,'a');
        for(var i=0; i<items.length; i++){
            var elem = items[i];

            // attach action to make the link clickable by AJAX
            addEvent(elem,'click',function(e){ return index.toggle(e,this); });

            // get the listitem the elem belongs to
            var listitem = elem.parentNode;
            while (listitem.tagName != 'LI') {
              listitem = listitem.parentNode;
            }
            //when there are uls under this listitem mark this listitem as opened
            if (listitem.getElementsByTagName('ul').length) {
              listitem.open = true;
            }
        }
    },

    /**
     * Open or close a subtree using AJAX
     * The contents of subtrees are "cached" untill the page is reloaded.
     * A "loading" indicator is shown only when the AJAX call is slow.
     *
     * @author Andreas Gohr <andi@splitbrain.org>
     * @author Ben Coburn <btcoburn@silicodon.net>
     */
    toggle: function(e,clicky){
        var listitem = clicky.parentNode.parentNode;

        listitem.open = !listitem.open;
        // listitem.open represents now the action to be done

        // if already open, close by removing the sublist
        var sublists = listitem.getElementsByTagName('ul');
        if(!listitem.open){
            if (sublists.length) {
              sublists[0].style.display='none';
            }
            listitem.className='closed';
            e.preventDefault();
            return false;
        }

        // just show if already loaded
        if(sublists.length && listitem.open){
            sublists[0].style.display='';
            listitem.className='open';
            e.preventDefault();
            return false;
        }

        // prepare an AJAX call to fetch the subtree
        var ajax = new sack(DOKU_BASE + 'lib/exe/ajax.php');
        ajax.AjaxFailedAlert = '';
        ajax.encodeURIString = false;
        if(ajax.failed) return true;

        //prepare the new ul
        var ul = document.createElement('ul');
        ul.className = 'idx';
        timeout = window.setTimeout(function(){
            // show the throbber as needed
            if (listitem.open) {
              ul.innerHTML = '<li><img src="'+DOKU_BASE+'lib/images/throbber.gif" alt="loading..." title="loading..." /></li>';
              listitem.appendChild(ul);
              listitem.className='open';
            }
        }, this.throbber_delay);
        ajax.elementObj = ul;
        ajax.afterCompletion = function(){
            window.clearTimeout(timeout);
            index.treeattach(ul);
            if (listitem.className!='open') {
              if (!listitem.open) {
                ul.style.display='none';
              }
              listitem.appendChild(ul);
              if (listitem.open) {
                listitem.className='open';
              }
            }
        };
        ajax.runAJAX(clicky.search.substr(1)+'&call=index');
        e.preventDefault();
        return false;
    }
};


addInitEvent(function(){
    index.treeattach($('index__tree'));
});


/* XXXXXXXXXX end of lib/scripts/index.js XXXXXXXXXX */



/* XXXXXXXXXX begin of lib/scripts/drag.js XXXXXXXXXX */

/**
 * Makes a DOM object draggable
 *
 * This is currently for movable DOM dialogs only. If needed it could be
 * extended to execute callbacks on special events...
 *
 * @link http://nofunc.org/Drag_Drop/
 */
var drag = {
    obj: null,
    handle: null,
    oX: 0,  // object X position
    oY: 0,  // object Y position
    eX: 0,  // event X delta
    eY: 0,  // event Y delta

    /**
     * Attaches the needed handlers to the given object
     *
     * This can be called for multiple objects, the right one is later
     * determined from the event itself. The handle is optional
     *
     * @param DOMObject obj    The object that should be draggable
     * @param DOMObject handle A handle on which the obj can be dragged
     */
    attach: function (obj,handle) {
        if(handle){
            handle.dragobject = obj;
            addEvent($(handle),'mousedown',drag.start);
        }else{
            addEvent($(obj),'mousedown',drag.start);
        }
    },

    /**
     * Starts the dragging operation
     */
    start: function (e){
        drag.handle = e.target;
        if(drag.handle.dragobject){
            drag.obj = drag.handle.dragobject;
        }else{
            drag.obj = drag.handle;
        }

        drag.handle.className += ' ondrag';
        drag.obj.className    += ' ondrag';

        drag.oX = parseInt(drag.obj.style.left);
        drag.oY = parseInt(drag.obj.style.top);
        drag.eX = drag.evX(e);
        drag.eY = drag.evY(e);

        addEvent(document,'mousemove',drag.drag);
        addEvent(document,'mouseup',drag.stop);

        e.preventDefault();
        e.stopPropagation();
        return false;
    },

    /**
     * Ends the dragging operation
     */
    stop: function(){
        drag.handle.className = drag.handle.className.replace(/ ?ondrag/,'');
        drag.obj.className    = drag.obj.className.replace(/ ?ondrag/,'');
        removeEvent(document,'mousemove',drag.drag);
        removeEvent(document,'mouseup',drag.stop);
        drag.obj = null;
        drag.handle = null;
    },

    /**
     * Moves the object during the dragging operation
     */
    drag: function(e) {
        if(drag.obj) {
            drag.obj.style.top  = (drag.evY(e)+drag.oY-drag.eY+'px');
            drag.obj.style.left = (drag.evX(e)+drag.oX-drag.eX+'px');
        }
    },

    /**
     * Returns the X position of the given event.
     */
    evX: function(e){
        return (e.pageX) ? e.pageX : e.clientX + document.body.scrollTop; //fixme shouldn't this be scrollLeft?
    },

    /**
     * Returns the Y position of the given event.
     */
    evY: function(e){
        return (e.pageY) ? e.pageY : e.clientY + document.body.scrollTop;
    }

};



/* XXXXXXXXXX end of lib/scripts/drag.js XXXXXXXXXX */



/* XXXXXXXXXX begin of lib/scripts/textselection.js XXXXXXXXXX */

/**
 * Text selection related functions.
 */

/**
 * selection prototype
 *
 * Object that capsulates the selection in a textarea. Returned by getSelection.
 *
 * @author Andreas Gohr <andi@splitbrain.org>
 */
function selection_class(){
    this.start     = 0;
    this.end       = 0;
    this.obj       = null;
    this.rangeCopy = null;
    this.scroll    = 0;
    this.fix       = 0;

    this.getLength = function(){
        return this.end - this.start;
    };

    this.getText = function(){
        if(!this.obj) return '';
        return this.obj.value.substring(this.start,this.end);
    }
}

/**
 * Get current selection/cursor position in a given textArea
 *
 * @link   http://groups.drupal.org/node/1210
 * @author Andreas Gohr <andi@splitbrain.org>
 * @link   http://linebyline.blogspot.com/2006/11/textarea-cursor-position-in-internet.html
 * @returns object - a selection object
 */
function getSelection(textArea) {
    var sel = new selection_class();

    sel.obj   = textArea;
    sel.start = textArea.value.length;
    sel.end   = textArea.value.length;

    textArea.focus();
    if(document.getSelection) {          // Mozilla et al.
        sel.start  = textArea.selectionStart;
        sel.end    = textArea.selectionEnd;
        sel.scroll = textArea.scrollTop;
    } else if(document.selection) {      // MSIE
        /*
         * This huge lump of code is neccessary to work around two MSIE bugs:
         *
         * 1. Selections trim newlines at the end of the code
         * 2. Selections count newlines as two characters
         */

        // The current selection
        sel.rangeCopy = document.selection.createRange().duplicate();

        var before_range = document.body.createTextRange();
        before_range.moveToElementText(textArea);                    // Selects all the text
        before_range.setEndPoint("EndToStart", sel.rangeCopy);     // Moves the end where we need it

        var before_finished = false, selection_finished = false;
        var before_text, selection_text;
        // Load the text values we need to compare
        before_text  = before_range.text;
        selection_text = sel.rangeCopy.text;

        sel.start = before_text.length;
        sel.end   = sel.start + selection_text.length;

        // Check each range for trimmed newlines by shrinking the range by 1 character and seeing
        // if the text property has changed.  If it has not changed then we know that IE has trimmed
        // a \r\n from the end.
        do {
            if (!before_finished) {
                if (before_range.compareEndPoints("StartToEnd", before_range) == 0) {
                    before_finished = true;
                } else {
                    before_range.moveEnd("character", -1);
                    if (before_range.text == before_text) {
                        sel.start += 2;
                        sel.end += 2;
                    } else {
                        before_finished = true;
                    }
                }
            }
            if (!selection_finished) {
                if (sel.rangeCopy.compareEndPoints("StartToEnd", sel.rangeCopy) == 0) {
                    selection_finished = true;
                } else {
                    sel.rangeCopy.moveEnd("character", -1);
                    if (sel.rangeCopy.text == selection_text) {
                        sel.end += 2;
                    } else {
                        selection_finished = true;
                    }
                }
            }
        } while ((!before_finished || !selection_finished));


        // count number of newlines in str to work around stupid IE selection bug
        var countNL = function(str) {
            var m = str.split("\r\n");
            if (!m || !m.length) return 0;
            return m.length-1;
        };
        sel.fix = countNL(sel.obj.value.substring(0,sel.start));

    }
    return sel;
}

/**
 * Set the selection
 *
 * You need to get a selection object via getSelection() first, then modify the
 * start and end properties and pass it back to this function.
 *
 * @link http://groups.drupal.org/node/1210
 * @author Andreas Gohr <andi@splitbrain.org>
 * @param object selection - a selection object as returned by getSelection()
 */
function setSelection(selection){
    if(document.getSelection){ // FF
        // what a pleasure in FF ;)
        selection.obj.setSelectionRange(selection.start,selection.end);
        if(selection.scroll) selection.obj.scrollTop = selection.scroll;
    } else if(document.selection) { // IE
        selection.rangeCopy.collapse(true);
        selection.rangeCopy.moveStart('character',selection.start - selection.fix);
        selection.rangeCopy.moveEnd('character',selection.end - selection.start);
        selection.rangeCopy.select();
    }
}

/**
 * Inserts the given text at the current cursor position or replaces the current
 * selection
 *
 * @author Andreas Gohr <andi@splitbrain.org>
 * @param string text          - the new text to be pasted
 * @param objct  selecttion    - selection object returned by getSelection
 * @param int    opts.startofs - number of charcters at the start to skip from new selection
 * @param int    opts.endofs   - number of characters at the end to skip from new selection
 * @param bool   opts.nosel    - set true if new text should not be selected
 */
function pasteText(selection,text,opts){
    if(!opts) opts = {};
    // replace the content

    selection.obj.value =
        selection.obj.value.substring(0, selection.start) + text +
        selection.obj.value.substring(selection.end, selection.obj.value.length);

    // set new selection
    selection.end = selection.start + text.length;

    // modify the new selection if wanted
    if(opts.startofs) selection.start += opts.startofs;
    if(opts.endofs)   selection.end   -= opts.endofs;

    // no selection wanted? set cursor to end position
    if(opts.nosel) selection.start = selection.end;

    setSelection(selection);
}


/**
 * Format selection
 *
 * Apply tagOpen/tagClose to selection in textarea, use sampleText instead
 * of selection if there is none.
 *
 * @author Andreas Gohr <andi@splitbrain.org>
 */
function insertTags(textAreaID, tagOpen, tagClose, sampleText){
    var txtarea = $(textAreaID);

    var selection = getSelection(txtarea);
    var text = selection.getText();
    var opts;

    // don't include trailing space in selection
    if(text.charAt(text.length - 1) == ' '){
        selection.end--;
        text = selection.getText();
    }

    if(!text){
        // nothing selected, use the sample text and select it
        text = sampleText;
        opts = {
            startofs: tagOpen.length,
            endofs: tagClose.length
        };
    }else{
        // place cursor at the end
        opts = {
            nosel: true
        };
    }

    // surround with tags
    text = tagOpen + text + tagClose;

    // do it
    pasteText(selection,text,opts);
}

/**
 * Wraps around pasteText() for backward compatibility
 *
 * @author Andreas Gohr <andi@splitbrain.org>
 */
function insertAtCarret(textAreaID, text){
    var txtarea = $(textAreaID);
    var selection = getSelection(txtarea);
    pasteText(selection,text,{nosel: true});
}



/* XXXXXXXXXX end of lib/scripts/textselection.js XXXXXXXXXX */



/* XXXXXXXXXX begin of lib/scripts/toolbar.js XXXXXXXXXX */


// used to identify pickers
var pickercounter=0;

/**
 * Create a toolbar
 *
 * @param  string tbid ID of the element where to insert the toolbar
 * @param  string edid ID of the editor textarea
 * @param  array  tb   Associative array defining the buttons
 * @author Andreas Gohr <andi@splitbrain.org>
 */
function initToolbar(tbid,edid,tb){
    var toolbar = $(tbid);
    if(!toolbar) return;
    var edit = $(edid);
    if(!edit) return;
    if(edit.readOnly) return;

    //empty the toolbar area:
    toolbar.innerHTML='';

    var cnt = tb.length;
    for(var i=0; i<cnt; i++){
        var actionFunc;

        // create new button
        var btn = createToolButton(tb[i]['icon'],
                                   tb[i]['title'],
                                   tb[i]['key']);


        // type is a tb function -> assign it as onclick
        actionFunc = 'tb_'+tb[i]['type'];
        if( isFunction(window[actionFunc]) ){
            addEvent(btn,'click', bind(window[actionFunc],btn,tb[i],edid));
            toolbar.appendChild(btn);
            continue;
        }

        // type is a init function -> execute it
        actionFunc = 'addBtnAction'+tb[i]['type'].charAt(0).toUpperCase()+tb[i]['type'].substring(1);
        if( isFunction(window[actionFunc]) ){
            if(window[actionFunc](btn, tb[i], edid)){
                toolbar.appendChild(btn);
            }
            continue;
        }

        alert('unknown toolbar type: '+tb[i]['type']+'  '+actionFunc);
    } // end for

}

/**
 * Button action for format buttons
 *
 * @param  DOMElement btn   Button element to add the action to
 * @param  array      props Associative array of button properties
 * @param  string     edid  ID of the editor textarea
 * @author Gabriel Birke <birke@d-scribe.de>
 * @author Andreas Gohr <andi@splitbrain.org>
 */
function tb_format(btn, props, edid) {
    var sample = props['title'];
    if(props['sample']){
        sample = props['sample'];
    }
    insertTags(edid,
               fixtxt(props['open']),
               fixtxt(props['close']),
               fixtxt(sample));
    pickerClose();
    return false;
}

/**
 * Button action for format buttons
 *
 * This works exactly as tb_format() except that, if multiple lines
 * are selected, each line will be formatted seperately
 *
 * @param  DOMElement btn   Button element to add the action to
 * @param  array      props Associative array of button properties
 * @param  string     edid  ID of the editor textarea
 * @author Gabriel Birke <birke@d-scribe.de>
 * @author Andreas Gohr <andi@splitbrain.org>
 */
function tb_formatln(btn, props, edid) {
    var sample = props['title'];
    if(props['sample']){
        sample = props['sample'];
    }
    sample = fixtxt(sample);

    props['open']  = fixtxt(props['open']);
    props['close'] = fixtxt(props['close']);

    // is something selected?
    var opts;
    var selection = getSelection($(edid));
    if(selection.getLength()){
        sample = selection.getText();
        opts = {nosel: true};
    }else{
        opts = {
            startofs: props['open'].length,
            endofs: props['close'].length
        };
    }

    sample = sample.split("\n").join(props['close']+"\n"+props['open']);
    sample = props['open']+sample+props['close'];

    pasteText(selection,sample,opts);

    pickerClose();
    return false;
}

/**
 * Button action for insert buttons
 *
 * @param  DOMElement btn   Button element to add the action to
 * @param  array      props Associative array of button properties
 * @param  string     edid  ID of the editor textarea
 * @author Gabriel Birke <birke@d-scribe.de>
 * @author Andreas Gohr <andi@splitbrain.org>
 */
function tb_insert(btn, props, edid) {
    insertAtCarret(edid,fixtxt(props['insert']));
    pickerClose();
    return false;
}

/**
 * Button action for the media popup
 *
 * @param  DOMElement btn   Button element to add the action to
 * @param  array      props Associative array of button properties
 * @param  string     edid  ID of the editor textarea
 * @author Andreas Gohr <andi@splitbrain.org>
 */
function tb_mediapopup(btn, props, edid) {
    window.open(
        DOKU_BASE+props['url']+encodeURIComponent(NS),
        props['name'],
        props['options']);
    return false;
}

/**
 * Button action for automatic headlines
 *
 * Insert a new headline based on the current section level
 *
 * @param  DOMElement btn   Button element to add the action to
 * @param  array      props Associative array of button properties
 * @param  string     edid  ID of the editor textarea
 * @author Andreas Gohr <andi@splitbrain.org>
 */
function tb_autohead(btn, props, edid){
    var lvl = currentHeadlineLevel(edid);

    // determine new level
    lvl += props['mod'];
    if(lvl < 1) lvl = 1;
    if(lvl > 5) lvl = 5;

    var tags = '=';
    for(var i=0; i<=5-lvl; i++) tags += '=';
    insertTags(edid, tags+' ', ' '+tags+"\n", props['text']);
    pickerClose();
    return false;
}


/**
 * Add button action for picker buttons and create picker element
 *
 * @param  DOMElement btn   Button element to add the action to
 * @param  array      props Associative array of button properties
 * @param  string     edid  ID of the editor textarea
 * @return boolean    If button should be appended
 * @author Gabriel Birke <birke@d-scribe.de>
 */
function addBtnActionPicker(btn, props, edid) {
    var pickerid = 'picker'+(pickercounter++);
    createPicker(pickerid, props, edid);
    addEvent(btn,'click',function(){
        pickerToggle(pickerid,btn);
        return false;
    });
    return true;
}

/**
 * Add button action for the link wizard button
 *
 * @param  DOMElement btn   Button element to add the action to
 * @param  array      props Associative array of button properties
 * @param  string     edid  ID of the editor textarea
 * @return boolean    If button should be appended
 * @author Andreas Gohr <gohr@cosmocode.de>
 */
function addBtnActionLinkwiz(btn, props, edid) {
    linkwiz.init($(edid));
    addEvent(btn,'click',function(){
        linkwiz.toggle();
        return false;
    });
    return true;
}

/**
 * Show/Hide a previosly created picker window
 *
 * @author Andreas Gohr <andi@splitbrain.org>
 */
function pickerToggle(pickerid,btn){
    var picker = $(pickerid);
    if(picker.style.marginLeft == '-10000px'){
        var x = findPosX(btn);
        var y = findPosY(btn);
        picker.style.left = (x+3)+'px';
        picker.style.top = (y+btn.offsetHeight+3)+'px';
        picker.style.marginLeft = '0px';
    }else{
        picker.style.marginLeft = '-10000px';
    }
}

/**
 * Close all open pickers
 *
 * @author Andreas Gohr <andi@splitbrain.org>
 */
function pickerClose(){
    var pobjs = getElementsByClass('picker');
    for(var i=0; i<pobjs.length; i++){
        pobjs[i].style.marginLeft = '-10000px';
    }
}


/**
 * Replaces \n with linebreaks
 */
function fixtxt(str){
    return str.replace(/\\n/g,"\n");
}



/* XXXXXXXXXX end of lib/scripts/toolbar.js XXXXXXXXXX */



/* XXXXXXXXXX begin of lib/scripts/edit.js XXXXXXXXXX */

/**
 * Functions for text editing (toolbar stuff)
 *
 * @todo most of the stuff in here should be revamped and then moved to toolbar.js
 * @author Andreas Gohr <andi@splitbrain.org>
 */

/**
 * Creates a toolbar button through the DOM
 *
 * Style the buttons through the toolbutton class
 *
 * @author Andreas Gohr <andi@splitbrain.org>
 */
function createToolButton(icon,label,key,id){
    var btn = document.createElement('button');
    var ico = document.createElement('img');

    // preapare the basic button stuff
    btn.className = 'toolbutton';
    btn.title = label;
    if(key){
        btn.title += ' ['+key.toUpperCase()+']';
        btn.accessKey = key;
    }

    // set IDs if given
    if(id){
        btn.id = id;
        ico.id = id+'_ico';
    }

    // create the icon and add it to the button
    if(icon.substr(0,1) == '/'){
        ico.src = icon;
    }else{
        ico.src = DOKU_BASE+'lib/images/toolbar/'+icon;
    }
    btn.appendChild(ico);

    return btn;
}

/**
 * Creates a picker window for inserting text
 *
 * The given list can be an associative array with text,icon pairs
 * or a simple list of text. Style the picker window through the picker
 * class or the picker buttons with the pickerbutton class. Picker
 * windows are appended to the body and created invisible.
 *
 * @param  string id    the ID to assign to the picker
 * @param  array  props the properties for the picker
 * @param  string edid  the ID of the textarea
 * @rteurn DOMobject    the created picker
 * @author Andreas Gohr <andi@splitbrain.org>
 */
function createPicker(id,props,edid){
    var icobase = props['icobase'];
    var list    = props['list'];

    // create the wrapping div
    var picker            = document.createElement('div');
    picker.className      = 'picker';
    if(props['class']){
        picker.className += ' '+props['class'];
    }
    picker.id               = id;
    picker.style.position   = 'absolute';
    picker.style.marginLeft = '-10000px'; // no display:none, to keep access keys working

    for(var key in list){
        if (!list.hasOwnProperty(key)) continue;

        if(isNaN(key)){
            // associative array -> treat as image/value pairs
            var btn = document.createElement('button');
            btn.className = 'pickerbutton';
            var ico = document.createElement('img');
            if(list[key].substr(0,1) == '/'){
                ico.src = list[key];
            }else{
                ico.src = DOKU_BASE+'lib/images/'+icobase+'/'+list[key];
            }
            btn.title     = key;
            btn.appendChild(ico);
            addEvent(btn,'click',bind(pickerInsert,key,edid));
            picker.appendChild(btn);
        }else if(isString(list[key])){
            // a list of text -> treat as text picker
            var btn = document.createElement('button');
            btn.className = 'pickerbutton';
            var txt = document.createTextNode(list[key]);
            btn.title     = list[key];
            btn.appendChild(txt);
            addEvent(btn,'click',bind(pickerInsert,list[key],edid));
            picker.appendChild(btn);
        }else{
            // a list of lists -> treat it as subtoolbar
            initToolbar(picker,edid,list);
            break; // all buttons handled already
        }

    }
    var body = document.getElementsByTagName('body')[0];
    body.appendChild(picker);
    return picker;
}

/**
 * Called by picker buttons to insert Text and close the picker again
 *
 * @author Andreas Gohr <andi@splitbrain.org>
 */
function pickerInsert(text,edid){
    insertAtCarret(edid,text);
    pickerClose();
}

/**
 * Add button action for signature button
 *
 * @param  DOMElement btn   Button element to add the action to
 * @param  array      props Associative array of button properties
 * @param  string     edid  ID of the editor textarea
 * @return boolean    If button should be appended
 * @author Gabriel Birke <birke@d-scribe.de>
 */
function addBtnActionSignature(btn, props, edid) {
    if(typeof(SIG) != 'undefined' && SIG != ''){
        addEvent(btn,'click',bind(insertAtCarret,edid,SIG));
        return true;
    }
    return false;
}

/**
 * Make intended formattings easier to handle
 *
 * Listens to all key inputs and handle indentions
 * of lists and code blocks
 *
 * Currently handles space, backspce and enter presses
 *
 * @author Andreas Gohr <andi@splitbrain.org>
 * @fixme handle tabs
 */
function keyHandler(e){
    if(e.keyCode != 13 &&
       e.keyCode != 8  &&
       e.keyCode != 32) return;
    var field     = e.target;
    var selection = getSelection(field);
    var search    = "\n"+field.value.substr(0,selection.start);
    var linestart = Math.max(search.lastIndexOf("\n"),
                             search.lastIndexOf("\r")); //IE workaround
    search = search.substr(linestart);


    if(e.keyCode == 13){ // Enter
        // keep current indention for lists and code
        var match = search.match(/(\n  +([\*-] ?)?)/);
        if(match){
            var scroll = field.scrollHeight;
            insertAtCarret(field.id,match[1]);
            field.scrollTop += (field.scrollHeight - scroll);
            e.preventDefault(); // prevent enter key
            return false;
        }
    }else if(e.keyCode == 8){ // Backspace
        // unindent lists
        var match = search.match(/(\n  +)([*-] ?)$/);
        if(match){
            var spaces = match[1].length-1;

            if(spaces > 3){ // unindent one level
                field.value = field.value.substr(0,linestart)+
                              field.value.substr(linestart+2);
                selection.start = selection.start - 2;
                selection.end   = selection.start;
            }else{ // delete list point
                field.value = field.value.substr(0,linestart)+
                              field.value.substr(selection.start);
                selection.start = linestart;
                selection.end   = linestart;
            }
            setSelection(selection);
            e.preventDefault(); // prevent backspace
            return false;
        }
    }else if(e.keyCode == 32){ // Space
        // intend list item
        var match = search.match(/(\n  +)([*-] )$/);
        if(match){
            field.value = field.value.substr(0,linestart)+'  '+
                          field.value.substr(linestart);
            selection.start = selection.start + 2;
            selection.end   = selection.start;
            setSelection(selection);
            e.preventDefault(); // prevent space
            return false;
        }
    }
}

//FIXME consolidate somewhere else
addInitEvent(function(){
    var field = $('wiki__text');
    if(!field) return;
    addEvent(field,'keydown',keyHandler);
});

/**
 * Determine the current section level while editing
 *
 * @author Andreas Gohr <gohr@cosmocode.de>
 */
function currentHeadlineLevel(textboxId){
    var field     = $(textboxId);
    var selection = getSelection(field);
    var search    = "\n"+field.value.substr(0,selection.start);
    var lasthl    = search.lastIndexOf("\n==");
    if(lasthl == -1 && field.form.prefix){
        // we need to look in prefix context
        search = field.form.prefix.value;
        lasthl    = search.lastIndexOf("\n==");
    }
    search    = search.substr(lasthl+1,6);

    if(search == '======') return 1;
    if(search.substr(0,5) == '=====') return 2;
    if(search.substr(0,4) == '====') return 3;
    if(search.substr(0,3) == '===') return 4;
    if(search.substr(0,2) == '==') return 5;

    return 0;
}


/**
 * global var used for not saved yet warning
 */
var textChanged = false;

/**
 * Check for changes before leaving the page
 */
function changeCheck(msg){
  if(textChanged){
    var ok = confirm(msg);
    if(ok){
        // remove a possibly saved draft using ajax
        var dwform = $('dw__editform');
        if(dwform){
            var params = 'call=draftdel';
            params += '&id='+encodeURIComponent(dwform.elements.id.value);

            var sackobj = new sack(DOKU_BASE + 'lib/exe/ajax.php');
            sackobj.AjaxFailedAlert = '';
            sackobj.encodeURIString = false;
            sackobj.runAJAX(params);
            // we send this request blind without waiting for
            // and handling the returned data
        }
    }
    return ok;
  }else{
    return true;
  }
}

/**
 * Add changeCheck to all Links and Forms (except those with a
 * JSnocheck class), add handlers to monitor changes
 *
 * Sets focus to the editbox as well
 *
 * @fixme this is old and crappy code. needs to be redone
 */
function initChangeCheck(msg){
    var edit_text   = document.getElementById('wiki__text');
    if(!edit_text) return;
    if(edit_text.readOnly) return;
    if(!$('dw__editform')) return;

    // add change check for links
    var links = document.getElementsByTagName('a');
    for(var i=0; i < links.length; i++){
        if(links[i].className.indexOf('JSnocheck') == -1){
            links[i].onclick = function(){
                                    var rc = changeCheck(msg);
                                    if(window.event) window.event.returnValue = rc;
                                    return rc;
                               };
        }
    }
    // add change check for forms
    var forms = document.forms;
    for(i=0; i < forms.length; i++){
        if(forms[i].className.indexOf('JSnocheck') == -1){
            forms[i].onsubmit = function(){
                                    var rc = changeCheck(msg);
                                    if(window.event) window.event.returnValue = rc;
                                    return rc;
                               };
        }
    }

    // reset change memory var on submit
    var btn_save        = document.getElementById('edbtn__save');
    btn_save.onclick    = function(){ textChanged = false; };
    var btn_prev        = document.getElementById('edbtn__preview');
    btn_prev.onclick    = function(){ textChanged = false; };

    // add change memory setter
    edit_text.onchange = function(){
        textChanged = true; //global var
        summaryCheck();
    };
    var summary = document.getElementById('edit__summary');
    addEvent(summary, 'change', summaryCheck);
    addEvent(summary, 'keyup', summaryCheck);
    if (textChanged) summaryCheck();

    // set focus
    edit_text.focus();
}

/**
 * Checks if a summary was entered - if not the style is changed
 *
 * @author Andreas Gohr <andi@splitbrain.org>
 */
function summaryCheck(){
    var sum = document.getElementById('edit__summary');
    if(sum.value === ''){
        sum.className='missing';
    }else{
        sum.className='edit';
    }
}


/**
 * Class managing the timer to display a warning on a expiring lock
 */
function locktimer_class(){
        this.sack     = null;
        this.timeout  = 0;
        this.timerID  = null;
        this.lasttime = null;
        this.msg      = '';
        this.pageid   = '';
};
var locktimer = new locktimer_class();
    locktimer.init = function(timeout,msg,draft){
        // init values
        locktimer.timeout  = timeout*1000;
        locktimer.msg      = msg;
        locktimer.draft    = draft;
        locktimer.lasttime = new Date();

        if(!$('dw__editform')) return;
        locktimer.pageid = $('dw__editform').elements.id.value;
        if(!locktimer.pageid) return;

        // init ajax component
        locktimer.sack = new sack(DOKU_BASE + 'lib/exe/ajax.php');
        locktimer.sack.AjaxFailedAlert = '';
        locktimer.sack.encodeURIString = false;
        locktimer.sack.onCompletion = locktimer.refreshed;

        // register refresh event
        addEvent($('dw__editform').elements.wikitext,'keypress',function(){locktimer.refresh();});

        // start timer
        locktimer.reset();
    };

    /**
     * (Re)start the warning timer
     */
    locktimer.reset = function(){
        locktimer.clear();
        locktimer.timerID = window.setTimeout("locktimer.warning()", locktimer.timeout);
    };

    /**
     * Display the warning about the expiring lock
     */
    locktimer.warning = function(){
        locktimer.clear();
        alert(locktimer.msg);
    };

    /**
     * Remove the current warning timer
     */
    locktimer.clear = function(){
        if(locktimer.timerID !== null){
            window.clearTimeout(locktimer.timerID);
            locktimer.timerID = null;
        }
    };

    /**
     * Refresh the lock via AJAX
     *
     * Called on keypresses in the edit area
     */
    locktimer.refresh = function(){
        var now = new Date();
        // refresh every minute only
        if(now.getTime() - locktimer.lasttime.getTime() > 30*1000){ //FIXME decide on time
            var params = 'call=lock&id='+encodeURIComponent(locktimer.pageid);
            if(locktimer.draft){
                var dwform = $('dw__editform');
                params += '&prefix='+encodeURIComponent(dwform.elements.prefix.value);
                params += '&wikitext='+encodeURIComponent(dwform.elements.wikitext.value);
                params += '&suffix='+encodeURIComponent(dwform.elements.suffix.value);
                params += '&date='+encodeURIComponent(dwform.elements.date.value);
            }
            locktimer.sack.runAJAX(params);
            locktimer.lasttime = now;
        }
    };


    /**
     * Callback. Resets the warning timer
     */
    locktimer.refreshed = function(){
        var data  = this.response;
        var error = data.charAt(0);
            data  = data.substring(1);

        $('draft__status').innerHTML=data;
        if(error != '1') return; // locking failed
        locktimer.reset();
    };
// end of locktimer class functions



/* XXXXXXXXXX end of lib/scripts/edit.js XXXXXXXXXX */



/* XXXXXXXXXX begin of lib/scripts/linkwiz.js XXXXXXXXXX */

/**
 * The Link Wizard
 *
 * @author Andreas Gohr <gohr@cosmocode.de>
 */
var linkwiz = {
    wiz:    null,
    entry:  null,
    result: null,
    timer:  null,
    sack:   null,
    textArea: null,
    selected: -1,
    selection: null,

    /**
     * Initialize the linkwizard by creating the needed HTML
     * and attaching the eventhandlers
     */
    init: function(textArea){
        // prepare AJAX object
        linkwiz.sack = new sack(DOKU_BASE + 'lib/exe/ajax.php');
        linkwiz.sack.AjaxFailedAlert = '';
        linkwiz.sack.encodeURIString = false;

        // create HTML Structure
        linkwiz.wiz = document.createElement('div');
        linkwiz.wiz.id = 'link__wiz';
        linkwiz.wiz.className     = 'picker';
        linkwiz.wiz.style.top  = (findPosY(textArea)+20)+'px';
        linkwiz.wiz.style.left = (findPosX(textArea)+80)+'px';
        linkwiz.wiz.style.marginLeft = '-10000px';

        linkwiz.wiz.innerHTML =
             '<div id="link__wiz_header">'+
             '<img src="'+DOKU_BASE+'lib/images/close.png" width="16" height="16" align="right" alt="" id="link__wiz_close" />'+
             LANG['linkwiz']+'</div>'+
             '<div>'+LANG['linkto']+' <input type="text" class="edit" id="link__wiz_entry" autocomplete="off" /></div>'+
             '<div id="link__wiz_result"></div>';
        textArea.form.parentNode.appendChild(linkwiz.wiz);
        linkwiz.textArea = textArea;
        linkwiz.result = $('link__wiz_result');
        linkwiz.entry = $('link__wiz_entry');

        // attach event handlers
        var obj;
        obj = $('link__wiz_close');
        obj.onclick = linkwiz.hide;

        linkwiz.sack.elementObj = linkwiz.result;
        addEvent(linkwiz.entry,'keyup',linkwiz.onEntry);
        addEvent(linkwiz.result,'click',linkwiz.onResultClick);
        drag.attach(linkwiz.wiz,$('link__wiz_header'));
    },

    /**
     * handle all keyup events in the entry field
     */
    onEntry: function(e){
        if(e.keyCode == 37 || e.keyCode == 39){ //left/right
            return true; //ignore
        }
        if(e.keyCode == 27){
            linkwiz.hide();
            e.preventDefault();
            e.stopPropagation();
            return false;
        }
        if(e.keyCode == 38){ //Up
            linkwiz.select(linkwiz.selected -1);
            e.preventDefault();
            e.stopPropagation();
            return false;
        }
        if(e.keyCode == 40){ //Down
            linkwiz.select(linkwiz.selected +1);
            e.preventDefault();
            e.stopPropagation();
            return false;
        }
        if(e.keyCode == 13){ //Enter
            if(linkwiz.selected > -1){
                var obj = linkwiz.getResult(linkwiz.selected);
                if(obj){
                    var a = obj.getElementsByTagName('A')[0];
                    linkwiz.resultClick(a);
                }
            }else if(linkwiz.entry.value){
                linkwiz.insertLink(linkwiz.entry.value);
            }

            e.preventDefault();
            e.stopPropagation();
            return false;
        }
        linkwiz.autocomplete();
    },

    /**
     * Get one of the result by index
     *
     * @param int result div to return
     * @returns DOMObject or null
     */
    getResult: function(num){
        var obj;
        var childs = linkwiz.result.getElementsByTagName('DIV');
        obj = childs[num];
        if(obj){
            return obj;
        }else{
            return null;
        }
    },

    /**
     * Select the given result
     */
    select: function(num){
        if(num < 0){
            linkwiz.deselect();
            return;
        }

        var obj = linkwiz.getResult(num);
        if(obj){
            linkwiz.deselect();
            obj.className += ' selected';

            // make sure the item is viewable in the scroll view
            // FIXME check IE compatibility
            if(obj.offsetTop > linkwiz.result.scrollTop + linkwiz.result.clientHeight){
                linkwiz.result.scrollTop += obj.clientHeight;
            }else if(obj.offsetTop - linkwiz.result.clientHeight < linkwiz.result.scrollTop){ // this works but isn't quite right, fixes welcome
                linkwiz.result.scrollTop -= obj.clientHeight;
            }
            // now recheck - if still not in view, the user used the mouse to scroll
            if( (obj.offsetTop > linkwiz.result.scrollTop + linkwiz.result.clientHeight) ||
                (obj.offsetTop < linkwiz.result.scrollTop) ){
                obj.scrollIntoView();
            }

            linkwiz.selected = num;
        }
    },

    /**
     * deselect a result if any is selected
     */
    deselect: function(){
        if(linkwiz.selected > -1){
            var obj = linkwiz.getResult(linkwiz.selected);
            if(obj){
                obj.className = obj.className.replace(/ ?selected/,'');
            }
        }
        linkwiz.selected = -1;
    },

    /**
     * Handle clicks in the result set an dispatch them to
     * resultClick()
     */
    onResultClick: function(e){
        if(e.target.tagName != 'A') return;
        e.stopPropagation();
        e.preventDefault();
        linkwiz.resultClick(e.target);
        return false;
    },

    /**
     * Handles the "click" on a given result anchor
     */
    resultClick: function(a){
        var id = a.title;
        if(id == '' || id.substr(id.length-1) == ':'){
            linkwiz.entry.value = id;
            linkwiz.autocomplete_exec();
        }else{
            linkwiz.entry.value = id;
            if(a.nextSibling && a.nextSibling.tagName == 'SPAN'){
                linkwiz.insertLink(a.nextSibling.innerHTML);
            }else{
                linkwiz.insertLink('');
            }
        }
    },

    /**
     * Insert the id currently in the entry box to the textarea,
     * replacing the current selection or at the curso postion.
     * When no selection is available the given title will be used
     * as link title instead
     */
    insertLink: function(title){
        if(!linkwiz.entry.value) return;

        var sel = getSelection(linkwiz.textArea);
        if(sel.start == 0 && sel.end == 0) sel = linkwiz.selection;

        var stxt = sel.getText();
        if(!stxt && !DOKU_UHC) stxt=title;

        // prepend colon inside namespaces for non namespace pages
        if(linkwiz.textArea.form['id'].value.indexOf(':') != -1 &&
           linkwiz.entry.value.indexOf(':') == -1){
            linkwiz.entry.value = ':'+linkwiz.entry.value;
        }

        var link = '[['+linkwiz.entry.value+'|';
        if(stxt) link += stxt;
        link += ']]';

        var so = linkwiz.entry.value.length+3;
        var eo = 2;

        pasteText(sel,link,{startofs: so, endofs: eo});
        linkwiz.hide();
    },

    /**
     * Start the page/namespace lookup timer
     *
     * Calls autocomplete_exec when the timer runs out
     */
    autocomplete: function(){
        if(linkwiz.timer !== null){
            window.clearTimeout(linkwiz.timer);
            linkwiz.timer = null;
        }

        linkwiz.timer = window.setTimeout(linkwiz.autocomplete_exec,350);
    },

    /**
     * Executes the AJAX call for the page/namespace lookup
     */
    autocomplete_exec: function(){
        linkwiz.deselect();
        linkwiz.result.innerHTML = '<img src="'+DOKU_BASE+'lib/images/throbber.gif" alt="" width="16" height="16" />';
        linkwiz.sack.runAJAX('call=linkwiz&q='+encodeURI(linkwiz.entry.value));
    },

    /**
     * Clears the result area
     */
    clear: function(){
        linkwiz.result.innerHTML = 'Search for a matching page name above, or browse through the pages on the right';
        linkwiz.entry.value = '';
    },

    /**
     * Show the linkwizard
     */
    show: function(){
        linkwiz.selection  = getSelection(linkwiz.textArea);
        linkwiz.wiz.style.marginLeft = '0px';
        linkwiz.entry.focus();
        linkwiz.autocomplete();
    },

    /**
     * Hide the link wizard
     */
    hide: function(){
        linkwiz.wiz.style.marginLeft = '-10000px';
        linkwiz.textArea.focus();
    },

    /**
     * Toggle the link wizard
     */
    toggle: function(){
        if(linkwiz.wiz.style.marginLeft == '-10000px'){
            linkwiz.show();
        }else{
            linkwiz.hide();
        }
    }
};



/* XXXXXXXXXX end of lib/scripts/linkwiz.js XXXXXXXXXX */



/* XXXXXXXXXX begin of lib/scripts/media.js XXXXXXXXXX */

/**
 * JavaScript functionalitiy for the media management popup
 *
 * @author Andreas Gohr <andi@splitbrain.org>
 */
var media_manager = {
    keepopen: false,
    hide: false,

    /**
     * Attach event handlers to all "folders" below the given element
     *
     * @author Andreas Gohr <andi@splitbrain.org>
     */
    treeattach: function(obj){
        if(!obj) return;

        var items = obj.getElementsByTagName('li');
        for(var i=0; i<items.length; i++){
            var elem = items[i];

            // attach action to make the +/- clickable
            var clicky = elem.getElementsByTagName('img')[0];
            clicky.style.cursor = 'pointer';
            addEvent(clicky,'click',function(event){ return media_manager.toggle(event,this); });

            // attach action load folder list via AJAX
            var link = elem.getElementsByTagName('a')[0];
            link.style.cursor = 'pointer';
            addEvent(link,'click',function(event){ return media_manager.list(event,this); });
        }
    },

    /**
     * Attach the image selector action to all links below the given element
     * also add the action to autofill the "upload as" field
     *
     * @author Andreas Gohr <andi@splitbrain.org>
     */
    selectorattach: function(obj){
        if(!obj) return;

        var items = getElementsByClass('select',obj,'a');
        for(var i=0; i<items.length; i++){
            var elem = items[i];
            elem.style.cursor = 'pointer';
            addEvent(elem,'click',function(event){ return media_manager.select(event,this); });
        }

        // hide syntax example
        items = getElementsByClass('example',obj,'div');
        for(var i=0; i<items.length; i++){
            elem = items[i];
            elem.style.display = 'none';
        }

        var file = $('upload__file');
        if(!file) return;
        addEvent(file,'change',media_manager.suggest);
    },

    /**
     * Attach deletion confirmation dialog to the delete buttons.
     *
     * Michael Klier <chi@chimeric.de>
     */
    confirmattach: function(obj){
        if(!obj) return;

        items = getElementsByClass('btn_media_delete',obj,'a');
        for(var i=0; i<items.length; i++){
            var elem = items[i];
            addEvent(elem,'click',function(e){
                if(e.target.tagName == 'IMG'){
                    var name = e.target.parentNode.title;
                }else{
                    var name = e.target.title;
                }
                if(!confirm(LANG['del_confirm'] + "\n" + name)) {
                    e.preventDefault();
                    return false;
                } else {
                    return true;
                }
            });
        }
    },

    /**
     * Creates checkboxes for additional options
     *
     * @author Andreas Gohr <andi@splitbrain.org>
     */
    attachoptions: function(obj){
        if(!obj) return;

        // keep open
        if(opener){
            var kobox  = document.createElement('input');
            kobox.type = 'checkbox';
            kobox.id   = 'media__keepopen';
            if(DokuCookie.getValue('keepopen')){
                kobox.checked  = true;
                kobox.defaultChecked = true; //IE wants this
                media_manager.keepopen = true;
            }
            addEvent(kobox,'click',function(event){ return media_manager.togglekeepopen(event,this); });

            var kolbl  = document.createElement('label');
            kolbl.htmlFor   = 'media__keepopen';
            kolbl.innerHTML = LANG['keepopen'];

            var kobr = document.createElement('br');

            obj.appendChild(kobox);
            obj.appendChild(kolbl);
            obj.appendChild(kobr);
        }

        // hide details
        var hdbox  = document.createElement('input');
        hdbox.type = 'checkbox';
        hdbox.id   = 'media__hide';
        if(DokuCookie.getValue('hide')){
            hdbox.checked = true;
            hdbox.defaultChecked = true; //IE wants this
            media_manager.hide    = true;
        }
        addEvent(hdbox,'click',function(event){ return media_manager.togglehide(event,this); });

        var hdlbl  = document.createElement('label');
        hdlbl.htmlFor   = 'media__hide';
        hdlbl.innerHTML = LANG['hidedetails'];

        var hdbr = document.createElement('br');

        obj.appendChild(hdbox);
        obj.appendChild(hdlbl);
        obj.appendChild(hdbr);
        media_manager.updatehide();
    },

    /**
     * Opens the searchfield
     *
     * @author Tobias Sarnowski <sarnowski@cosmocode.de>
     */
    showsearchfield: function(event,link){
        // prepare an AJAX call to fetch the search
        var ajax = new sack(DOKU_BASE + 'lib/exe/ajax.php');
        ajax.AjaxFailedAlert = '';
        ajax.encodeURIString = false;
        if(ajax.failed) return true;

        cleanMsgArea();

        var content = $('media__content');
        content.innerHTML = '<img src="'+DOKU_BASE+'lib/images/loading.gif" alt="..." class="load" />';

        ajax.elementObj = content;
        ajax.afterCompletion = function(){
            media_manager.selectorattach(content);
            media_manager.confirmattach(content);
            media_manager.updatehide();
        };
        ajax.runAJAX(link.search.substr(1)+'&call=mediasearchlist');
        return false;
    },

    /**
     * Toggles the keep open state
     *
     * @author Andreas Gohr <andi@splitbrain.org>
     */
    togglekeepopen: function(event,cb){
        if(cb.checked){
            DokuCookie.setValue('keepopen',1);
            media_manager.keepopen = true;
        }else{
            DokuCookie.setValue('keepopen','');
            media_manager.keepopen = false;
        }
    },

    /**
     * Toggles the hide details state
     *
     * @author Andreas Gohr <andi@splitbrain.org>
     */
    togglehide: function(event,cb){
        if(cb.checked){
            DokuCookie.setValue('hide',1);
            media_manager.hide = true;
        }else{
            DokuCookie.setValue('hide','');
            media_manager.hide = false;
        }
        media_manager.updatehide();
    },

    /**
     * Sets the visibility of the image details accordingly to the
     * chosen hide state
     *
     * @author Andreas Gohr <andi@splitbrain.org>
     */
    updatehide: function(){
        var obj = $('media__content');
        if(!obj) return;
        var details = getElementsByClass('detail',obj,'div');
        for(var i=0; i<details.length; i++){
            if(media_manager.hide){
                details[i].style.display = 'none';
            }else{
                details[i].style.display = '';
            }
        }
    },

    /**
     * Insert the clicked image into the opener's textarea
     *
     * @author Andreas Gohr <andi@splitbrain.org>
     */
    select: function(event,link){
        var id = link.name.substr(2);

        if(!opener){
            // if we don't run in popup display example
            var ex = $('ex_'+id.replace(/:/g,'_'));
            if(ex.style.display == ''){
                ex.style.display = 'none';
            }else{
                ex.style.display = '';
            }
            return false;
        }
        opener.insertTags('wiki__text','{{'+id+'|','}}','');

        if(!media_manager.keepopen) window.close();
        opener.focus();
        return false;
    },

    /**
     * list the content of a namespace using AJAX
     *
     * @author Andreas Gohr <andi@splitbrain.org>
     */
    list: function(event,link){
        // prepare an AJAX call to fetch the subtree
        var ajax = new sack(DOKU_BASE + 'lib/exe/ajax.php');
        ajax.AjaxFailedAlert = '';
        ajax.encodeURIString = false;
        if(ajax.failed) return true;

        cleanMsgArea();

        var content = $('media__content');
        content.innerHTML = '<img src="'+DOKU_BASE+'lib/images/loading.gif" alt="..." class="load" />';

        ajax.elementObj = content;
        ajax.afterCompletion = function(){
            media_manager.selectorattach(content);
            media_manager.confirmattach(content);
            media_manager.updatehide();
            media_manager.initFlashUpload();
        };
        ajax.runAJAX(link.search.substr(1)+'&call=medialist');
        return false;
    },


    /**
     * Open or close a subtree using AJAX
     *
     * @author Andreas Gohr <andi@splitbrain.org>
     */
    toggle: function(event,clicky){
        var listitem = clicky.parentNode;

        // if already open, close by removing the sublist
        var sublists = listitem.getElementsByTagName('ul');
        if(sublists.length){
            listitem.removeChild(sublists[0]);
            clicky.src = DOKU_BASE+'lib/images/plus.gif';
            return false;
        }

        // get the enclosed link (is always the first one)
        var link = listitem.getElementsByTagName('a')[0];

        // prepare an AJAX call to fetch the subtree
        var ajax = new sack(DOKU_BASE + 'lib/exe/ajax.php');
        ajax.AjaxFailedAlert = '';
        ajax.encodeURIString = false;
        if(ajax.failed) return true;

        //prepare the new ul
        var ul = document.createElement('ul');
        //fixme add classname here
        listitem.appendChild(ul);
        ajax.elementObj = ul;
        ajax.afterCompletion = function(){ media_manager.treeattach(ul); };
        ajax.runAJAX(link.search.substr(1)+'&call=medians');
        clicky.src = DOKU_BASE+'lib/images/minus.gif';
        return false;
    },

    /**
     * Prefills the wikiname.
     *
     * @author Andreas Gohr <andi@splitbrain.org>
     */
    suggest: function(){
        var file = $('upload__file');
        var name = $('upload__name');
        if(!file || !name) return;

        var text = file.value;
        text = text.substr(text.lastIndexOf('/')+1);
        text = text.substr(text.lastIndexOf('\\')+1);
        name.value = text;
    },


    initFlashUpload: function(){
        if(!hasFlash(8)) return;
        var oform  = $('dw__upload');
        var oflash = $('dw__flashupload');
        if(!oform || !oflash) return;

        var clicky = document.createElement('img');
        clicky.src     = DOKU_BASE+'lib/images/multiupload.png';
        clicky.title   = LANG['mu_btn'];
        clicky.alt     = LANG['mu_btn'];
        clicky.style.cursor = 'pointer';
        clicky.onclick = function(){
                            oform.style.display  = 'none';
                            oflash.style.display = '';
                         };
        oform.appendChild(clicky);
    }
};

addInitEvent(function(){
    media_manager.treeattach($('media__tree'));
    media_manager.selectorattach($('media__content'));
    media_manager.confirmattach($('media__content'));
    media_manager.attachoptions($('media__opts'));
    media_manager.initFlashUpload();
});


/* XXXXXXXXXX end of lib/scripts/media.js XXXXXXXXXX */



/* XXXXXXXXXX begin of lib/tpl/default/script.js XXXXXXXXXX */



/* XXXXXXXXXX end of lib/tpl/default/script.js XXXXXXXXXX */



/* XXXXXXXXXX begin of lib/plugins/acl/script.js XXXXXXXXXX */

acl = {
    init: function(){
        this.ctl = $('acl_manager');
        if(!this.ctl) return;

        var sel = $('acl__user').getElementsByTagName('select')[0];

        addEvent(sel,'change',acl.userselhandler);
        addEvent($('acl__tree'),'click',acl.treehandler);
        addEvent($('acl__user').getElementsByTagName('input')[1],'click',acl.loadinfo);
    },


    /**
     * Handle user dropdown
     */
    userselhandler: function(e){
        // make entry field visible/invisible
        if(this.value == '__g__' || this.value == '__u__'){
            $('acl__user').getElementsByTagName('input')[0].style.display = ''; //acl_w
            $('acl__user').getElementsByTagName('input')[1].style.display = ''; //submit
        }else{
            $('acl__user').getElementsByTagName('input')[0].style.display = 'none';
            $('acl__user').getElementsByTagName('input')[1].style.display = 'none';
        }

        acl.loadinfo();
    },

    /**
     * Load the current permission info and edit form
     *
     * @param frm - Form element with needed data
     */
    loadinfo: function(){
        // get form
        var frm = $('acl__detail').getElementsByTagName('form')[0];

        // prepare an AJAX call
        var ajax = new sack(DOKU_BASE + 'lib/plugins/acl/ajax.php');
        ajax.AjaxFailedAlert = '';
        ajax.encodeURIString = false;
        if(ajax.failed) return true;

        // prepare data
        var data = Array();
        data[0] = ajax.encVar('ns',frm.elements['ns'].value);
        data[1] = ajax.encVar('id',frm.elements['id'].value);
        data[2] = ajax.encVar('acl_t',frm.elements['acl_t'].value);
        data[3] = ajax.encVar('acl_w',frm.elements['acl_w'].value);
        data[4] = ajax.encVar('ajax','info');

        ajax.elementObj = $('acl__info');

        ajax.runAJAX(data.join('&'));
        return false;
    },

    /**
     * parse URL attributes into a associative array
     *
     * @todo put into global script lib?
     */
    parseatt: function(str){
        if(str[0] == '?') str = str.substr(1);
        var attributes = {};
        var all = str.split('&');
        for(var i=0; i<all.length; i++){
            var att = all[i].split('=');
            attributes[att[0]] = decodeURIComponent(att[1]);
        }
        return attributes;
    },

    /**
     * htmlspecialchars equivalent
     *
     * @todo put in gloabl scripts lib?
     */
    hsc: function(str) {
        str = str.replace(/&/g,"&amp;");
        str = str.replace(/\"/g,"&quot;");
        str = str.replace(/\'/g,"&#039;");
        str = str.replace(/</g,"&lt;");
        str = str.replace(/>/g,"&gt;");
        return str;
    },


    /**
     * Open or close a subtree using AJAX
     *
     * @author Andreas Gohr <andi@splitbrain.org>
     */
    treetoggle: function(clicky){
        var listitem = clicky.parentNode.parentNode;

        // if already open, close by removing the sublist
        var sublists = listitem.getElementsByTagName('ul');
        if(sublists.length){
            listitem.removeChild(sublists[0]);
            clicky.src = DOKU_BASE+'lib/images/plus.gif';
            clicky.alt = '+';
            return false;
        }

        // get the enclosed link (is always the first one)
        var link = listitem.getElementsByTagName('a')[0];

        // prepare an AJAX call to fetch the subtree
        var ajax = new sack(DOKU_BASE + 'lib/plugins/acl/ajax.php');
        ajax.AjaxFailedAlert = '';
        ajax.encodeURIString = false;
        if(ajax.failed) return true;

        //prepare the new ul
        var ul = document.createElement('ul');
        listitem.appendChild(ul);
        ajax.elementObj = ul;
        ajax.runAJAX(link.search.substr(1)+'&ajax=tree');
        clicky.src = DOKU_BASE+'lib/images/minus.gif';
        return false;
    },

    /**
     * Handles all clicks in the tree, dispatching the right action based on the
     * clicked element
     */
    treehandler: function(e){
        if(e.target.src){ // is it an image?
            acl.treetoggle(e.target);
        } else if(e.target.href){ // is it a link?
            // remove highlighting
            var obj = getElementsByClass('cur',$('acl__tree'),'a');
            for(var i=0; i<obj.length; i++){
                obj[i].className = obj[i].className.replace(/ cur/,'');
            }

            // add new highlighting
            e.target.className += ' cur';

            // set new page to detail form
            var frm = $('acl__detail').getElementsByTagName('form')[0];
            if(e.target.className.search(/wikilink1/) > -1){
                frm.elements['ns'].value = '';
                frm.elements['id'].value = acl.hsc(acl.parseatt(e.target.search)['id']);
            }else if(e.target.className.search(/idx_dir/) > -1){
                frm.elements['ns'].value = acl.hsc(acl.parseatt(e.target.search)['ns']);
                frm.elements['id'].value = '';
            }

            acl.loadinfo();
        }

        e.stopPropagation();
        e.preventDefault();
        return false;
    }

};

addInitEvent(acl.init);


/* XXXXXXXXXX end of lib/plugins/acl/script.js XXXXXXXXXX */



/* XXXXXXXXXX begin of lib/plugins/gallery/script.js XXXXXXXXXX */

/**
 * Script for the Gallery Plugin to add nifty inline image viewing.
 *
 * It's based upon lightbox plus by Takuya Otani which is based upon
 * lightbox by Lokesh Dhakar.
 *
 * For the DokuWiki plugin the following modifications were made:
 *
 * - addEvent removed (is shipped with DokuWiki)
 * - IDs were changed to avoid clashs
 * - previous and next buttons added
 * - keyboard support added
 * - neighbor preloading (not sure if it works)
 *
 * @license Creative Commons Attribution 2.5 License
 * @author  Takuya Otani <takuya.otani@gmail.com>
 * @link    http://serennz.cool.ne.jp/sb/sp/lightbox/
 * @author  Lokesh Dhakar <lokesh@huddletogether.com>
 * @link    http://www.huddletogether.com/projects/lightbox/
 * @author  Andreas Gohr <andi@splitbrain.org>
 */

/* Original copyright notices follow:

  lightbox_plus.js
  == written by Takuya Otani <takuya.otani@gmail.com> ===
  == Copyright (C) 2006 SimpleBoxes/SerendipityNZ Ltd. ==

    Copyright (C) 2006 Takuya Otani/SimpleBoxes - http://serennz.cool.ne.jp/sb/
    Copyright (C) 2006 SerendipityNZ - http://serennz.cool.ne.jp/snz/

    This script is licensed under the Creative Commons Attribution 2.5 License
    http://creativecommons.org/licenses/by/2.5/

    basically, do anything you want, just leave my name and link.

    Original script : Lightbox JS : Fullsize Image Overlays
    Copyright (C) 2005 Lokesh Dhakar - http://www.huddletogether.com
    For more information on this script, visit:
    http://huddletogether.com/projects/lightbox/
*/



/**
 * This variable will enable the lightbox mode for every normal image
 * embedded through the normal wiki image syntax and using the ?direct
 * parameter.
 *
 * If you don't like that behavior, set this variable to 0.
 */
var lightboxForEveryImg = 0;

function WindowSize()
{ // window size object
    this.w = 0;
    this.h = 0;
    return this.update();
}
WindowSize.prototype.update = function()
{
    var d = document;
    this.w =
      (window.innerWidth) ? window.innerWidth
    : (d.documentElement && d.documentElement.clientWidth) ? d.documentElement.clientWidth
    : d.body.clientWidth;
    this.h =
      (window.innerHeight) ? window.innerHeight
    : (d.documentElement && d.documentElement.clientHeight) ? d.documentElement.clientHeight
    : d.body.clientHeight;
    return this;
};
function PageSize()
{ // page size object
    this.win = new WindowSize();
    this.w = 0;
    this.h = 0;
    return this.update();
}
PageSize.prototype.update = function()
{
    var d = document;
    this.w =
      (window.innerWidth && window.scrollMaxX) ? window.innerWidth + window.scrollMaxX
    : (d.body.scrollWidth > d.body.offsetWidth) ? d.body.scrollWidth
    : d.body.offsetWidt;
    this.h =
      (window.innerHeight && window.scrollMaxY) ? window.innerHeight + window.scrollMaxY
    : (d.body.scrollHeight > d.body.offsetHeight) ? d.body.scrollHeight
    : d.body.offsetHeight;
    this.win.update();
    if (this.w < this.win.w) this.w = this.win.w;
    if (this.h < this.win.h) this.h = this.win.h;
    return this;
};
function PagePos()
{ // page position object
    this.x = 0;
    this.y = 0;
    return this.update();
}
PagePos.prototype.update = function()
{
    var d = document;
    this.x =
      (window.pageXOffset) ? window.pageXOffset
    : (d.documentElement && d.documentElement.scrollLeft) ? d.documentElement.scrollLeft
    : (d.body) ? d.body.scrollLeft
    : 0;
    this.y =
      (window.pageYOffset) ? window.pageYOffset
    : (d.documentElement && d.documentElement.scrollTop) ? d.documentElement.scrollTop
    : (d.body) ? d.body.scrollTop
    : 0;
    return this;
};
function UserAgent()
{ // user agent information
    var ua = navigator.userAgent;
    this.isWinIE = this.isMacIE = false;
    this.isGecko  = ua.match(/Gecko\//);
    this.isSafari = ua.match(/AppleWebKit/);
    this.isOpera  = window.opera;
    if (document.all && !this.isGecko && !this.isSafari && !this.isOpera) {
        this.isWinIE = ua.match(/Win/);
        this.isMacIE = ua.match(/Mac/);
        this.isNewIE = (ua.match(/MSIE 5\.5/) || ua.match(/MSIE 6\.0/));
    }
    return this;
}
// === lightbox ===
function LightBox(option)
{
    var self = this;
    self._imgs = new Array();
    self._wrap = null;
    self._box  = null;
    self._open = -1;
    self._page = new PageSize();
    self._pos  = new PagePos();
    self._ua   = new UserAgent();
    self._expandable = false;
    self._expanded = false;
    self._expand = option.expandimg;
    self._shrink = option.shrinkimg;
    return self._init(option);
}
LightBox.prototype = {
    _init : function(option)
    {
        var self = this;
        var d = document;
        if (!d.getElementsByTagName) return;
        var links = d.getElementsByTagName("a");
        for (var i=0;i<links.length;i++) {
            var anchor = links[i];
            var num = self._imgs.length;

            //check if this is a direct link to an image
            if ( (anchor.getAttribute("href") && anchor.getAttribute("rel") == "lightbox") ||
                 (lightboxForEveryImg && anchor.getAttribute("class") &&
                  anchor.getAttribute("class").match("media") &&
                  anchor.firstChild.nodeName.toLowerCase().match("img") &&
                  anchor.getAttribute("href") &&
                  anchor.getAttribute("href").match("lib/exe/fetch.php|_media/")) ){
                // okay add lightbox
            }else{
                continue;
            }


            // initialize item
            self._imgs[num] = {src:anchor.getAttribute("href"),w:-1,h:-1,title:'',caption:'',cls:anchor.className};
            if (anchor.getAttribute("title"))
                self._imgs[num].title = anchor.getAttribute("title");
            else if (anchor.firstChild && anchor.firstChild.getAttribute && anchor.firstChild.getAttribute("title"))
                self._imgs[num].title = anchor.firstChild.getAttribute("title");
            if (anchor.firstChild && anchor.firstChild.getAttribute &&
                anchor.firstChild.getAttribute("longdesc")) {
                self._imgs[num].caption = anchor.firstChild.getAttribute("longdesc");
            }
            anchor.onclick = self._genOpener(num); // set closure to onclick event
        }
        var body = d.getElementsByTagName("body")[0];
        self._wrap = self._createWrapOn(body,option.loadingimg);
        self._box  = self._createBoxOn(body,option);
        return self;
    },
    _genOpener : function(num)
    {
        var self = this;
        return function() {
            self._show(num);
            if(window.event) window.event.returnValue = false;
            return false;
        }
    },
    _createWrapOn : function(obj,imagePath)
    {
        var self = this;
        if (!obj) return null;
        // create wrapper object, translucent background
        var wrap = document.createElement('div');
        wrap.id = 'gallery__overlay';
        with (wrap.style) {
            display = 'none';
            position = 'fixed';
            top = '0px';
            left = '0px';
            zIndex = '50';
            width = '100%';
            height = '100%';
        }
        if (self._ua.isWinIE) wrap.style.position = 'absolute';
        addEvent(wrap,"click",function() { self._close(); });
        obj.appendChild(wrap);
        // create loading image, animated image
        var imag = new Image;
        imag.onload = function() {
            var spin = document.createElement('img');
            spin.id = 'gallery__loadingImage';
            spin.src = imag.src;
            spin.style.position = 'relative';
            self._set_cursor(spin);
            addEvent(spin,'click',function() { self._close(); });
            wrap.appendChild(spin);
            imag.onload = function(){};
        };
        if (imagePath != '') imag.src = imagePath;
        return wrap;
    },
    _createBoxOn : function(obj,option)
    {
        var self = this;
        if (!obj) return null;
        // create lightbox object, frame rectangle
        var box = document.createElement('div');
        box.id = 'gallery__lightbox';
        with (box.style) {
            display = 'none';
            position = 'absolute';
            zIndex = '60';
        }
        obj.appendChild(box);
        // create image object to display a target image
        var img = document.createElement('img');
        img.id = 'gallery__lightboxImage';
        self._set_cursor(img);
        addEvent(img,'click',function(){ self._close(); });
        addEvent(img,'mouseover',function(){ self._show_action(); });
        addEvent(img,'mouseout',function(){ self._hide_action(); });
        box.appendChild(img);
        var zoom = document.createElement('img');
        zoom.id = 'gallery__actionImage';
        with (zoom.style) {
            display = 'none';
            position = 'absolute';
            top = '15px';
            left = '15px';
            zIndex = '70';
        }
        self._set_cursor(zoom);
        zoom.src = self._expand;
        addEvent(zoom,'mouseover',function(){ self._show_action(); });
        addEvent(zoom,'click', function() { self._zoom(); });
        box.appendChild(zoom);
        addEvent(window,'resize',function(){ self._set_size(true); });
        // close button
        if (option.closeimg) {
            var btn = document.createElement('img');
            btn.id = 'gallery__closeButton';
            with (btn.style) {
                display = 'inline';
                position = 'absolute';
                right = '10px';
                top = '10px';
                zIndex = '80';
            }
            btn.src = option.closeimg;
            self._set_cursor(btn);
            addEvent(btn,'click',function(){ self._close(); });
            box.appendChild(btn);
        }
        // next button
        if (option.nextimg) {
            var btn = document.createElement('img');
            btn.id = 'gallery__nextButton';
            with (btn.style) {
                display = 'inline';
                position = 'absolute';
                right = '10px';
                bottom = '10px';
                zIndex = '80';
            }
            btn.src = option.nextimg;
            self._set_cursor(btn);
            addEvent(btn,'click',function(){ self._move(+1) });
            box.appendChild(btn);
        }
        // prev button
        if (option.previmg) {
            var btn = document.createElement('img');
            btn.id = 'gallery__prevButton';
            with (btn.style) {
                display = 'inline';
                position = 'absolute';
                left = '10px';
                bottom = '10px';
                zIndex = '80';
            }
            btn.src = option.previmg;
            self._set_cursor(btn);
            addEvent(btn,'click',function(){ self._move(-1) });
            box.appendChild(btn);
        }
        // caption text
        var caption = document.createElement('span');
        caption.id = 'gallery__lightboxCaption';
        with (caption.style) {
            display = 'none';
            position = 'absolute';
            zIndex = '80';
        }
        box.appendChild(caption);
        return box;
    },
    _set_photo_size : function()
    {
        var self = this;
        if (self._open == -1) return;
        var imag = self._box.firstChild;
        var targ = { w:self._page.win.w - 30, h:self._page.win.h - 40 };
        var orig = { w:self._imgs[self._open].w, h:self._imgs[self._open].h };

        // shrink image with the same aspect
        var ratio = 1.0;
        if ((orig.w >= targ.w || orig.h >= targ.h) && orig.h && orig.w)
            ratio = ((targ.w / orig.w) < (targ.h / orig.h)) ? targ.w / orig.w : targ.h / orig.h;
        imag.width  = Math.floor(orig.w * ratio);
        imag.height = Math.floor(orig.h * ratio);
        self._expandable = (ratio < 1.0) ? true : false;
        if (self._ua.isWinIE) self._box.style.display = "block";
        self._box.style.top  = [self._pos.y + (self._page.win.h - imag.height - 33) / 2,'px'].join('');
        self._box.style.left = [((self._page.win.w - imag.width - 30) / 2),'px'].join('');
        self._show_caption(true);
    },
    _set_size : function(onResize)
    {
        var self = this;
        if (self._open == -1) return;
        self._page.update();
        self._pos.update();
        var spin = self._wrap.firstChild;
        if (spin) {
            var top = (self._page.win.h - spin.height) / 2;
            if (self._wrap.style.position == 'absolute') top += self._pos.y;
            spin.style.top  = [top,'px'].join('');
            spin.style.left = [(self._page.win.w - spin.width - 30) / 2,'px'].join('');
        }
        if (self._ua.isWinIE) {
            self._wrap.style.width  = [self._page.win.w,'px'].join('');
            self._wrap.style.height = [self._page.h,'px'].join('');
        }
        if (onResize) self._set_photo_size();
    },
    _show_action : function()
    {
        var self = this;
        if (self._open == -1 || !self._expandable) return;
        var obj = document.getElementById('gallery__actionImage');
        if (!obj) return;
        obj.src = (self._expanded) ? self._shrink : self._expand;
        obj.style.display = 'inline';
    },
    _hide_action : function()
    {
        var self = this;
        var obj = document.getElementById('gallery__actionImage');
        if (obj) obj.style.display = 'none';
    },
    _zoom : function()
    {
        var self = this;
        if (self._expanded) {
            self._set_photo_size();
            self._expanded = false;
        } else if (self._open > -1) {
            var imag = self._box.firstChild;
            self._box.style.top  = [self._pos.y,'px'].join('');
            self._box.style.left = '0px';
            imag.width  = self._imgs[self._open].w;
            imag.height = self._imgs[self._open].h;
            self._show_caption(false);
            self._expanded = true;
        }
        self._show_action();
    },
    _show_caption : function(enable)
    {
        var self = this;
        var caption = document.getElementById('gallery__lightboxCaption');
        if (!caption) return;
        if (caption.innerHTML.length == 0 || !enable) {
            caption.style.display = 'none';
        } else { // now display caption
            var imag = self._box.firstChild;
            with (caption.style) {
                top = [imag.height + 10,'px'].join(''); // 10 is top margin of lightbox
                left = '0px';
                width = [imag.width + 20,'px'].join(''); // 20 is total side margin of lightbox
                height = '';
                paddingBottom = '3px';
                display = 'block';
            }
        }
    },
    _move : function(by)
    {
        var self = this;
        var num  = self._open + by;
        // wrap around at start and end
        if(num < 0) num = self._imgs.length - 1;
        if(num >= self._imgs.length) num = 0;

        self._disable_keyboard();
        self._hide_action();
        self._box.style.display  = "none";
        self._show(num);
    },
    _show : function(num)
    {
        var self = this;
        var imag = new Image;
        if (num < 0 || num >= self._imgs.length) return;
        var loading = document.getElementById('gallery__loadingImage');
        var caption = document.getElementById('gallery__lightboxCaption');
        self._open = num; // set opened image number
        self._set_size(false); // calc and set wrapper size
        self._wrap.style.display = "block";
        if (loading) loading.style.display = 'inline';
        imag.onload = function() {
            if (self._imgs[self._open].w == -1) {
                // store original image width and height
                self._imgs[self._open].w = imag.width;
                self._imgs[self._open].h = imag.height;
            }
            if (caption) caption.innerHTML = '<b>'+self._imgs[self._open].title + '</b><br />' +
                                             self._imgs[self._open].caption;
            self._set_photo_size(); // calc and set lightbox size
            self._hide_action();
            self._box.style.display = "block";
            self._box.firstChild.src = imag.src;
            self._box.firstChild.setAttribute('title',self._imgs[self._open].title);
            if (loading) loading.style.display = 'none';
        };
        self._expandable = false;
        self._expanded = false;
        self._enable_keyboard();
        imag.src = self._imgs[self._open].src;
        self._preload_neighbors(num);
    },
    _preload_neighbors: function(num){
        var self = this;

        if((self._imgs.length - 1) > num){
            var preloadNextImage = new Image();
            preloadNextImage.src = self._imgs[num + 1].src;
        }
        if(num > 0){
            var preloadPrevImage = new Image();
            preloadPrevImage.src = self._imgs[num - 1].src;
        }
    },
    _set_cursor : function(obj)
    {
        var self = this;
        if (self._ua.isWinIE && !self._ua.isNewIE) return;
        obj.style.cursor = 'pointer';
    },
    _close : function()
    {
        var self = this;
        self._open = -1;
        self._disable_keyboard();
        self._hide_action();
        self._wrap.style.display = "none";
        self._box.style.display  = "none";
    },
    _enable_keyboard: function()
    {
        //globally store refernce to current lightbox object:
        __lightbox = this;
        addEvent(document,'keydown',this._keyboard_action);
    },
    _disable_keyboard: function()
    {
        //remove global pointer:
        delete __lightbox;
        removeEvent(document,'keydown',this._keyboard_action);
    },
    _keyboard_action: function(e) {
        var self = __lightbox;
        var keycode = 0;

        if(e.which){ // mozilla
            keycode = e.which;
        }else{ // IE
            keycode = event.keyCode;
        }

        var key = String.fromCharCode(keycode).toLowerCase();
        if((key == 'x') || (key == 'c') || (keycode == 27)){   // close lightbox
            self._close();
        } else if( (key == 'p') || (keycode == 37) ){  // display previous image
            self._move(-1);
        } else if(key == 'n' || (keycode == 39) ){  // display next image
            self._move(+1);
        }
    }
};

/**
 * Add a quicklink to the media popup
 */
function gallery_plugin(){
    var opts = $('media__opts');
    if(!opts) return;
    if(!window.opener) return;

    var glbl = document.createElement('label');
    var glnk = document.createElement('a');
    var gbrk = document.createElement('br');
    glnk.name         = 'gallery_plugin';
    glnk.innerHTML    = 'Add namespace as gallery';
    glnk.style.cursor = 'pointer';

    glnk.onclick = function(){
        var h1 = $('media__ns');
        if(!h1) return;
        var ns = h1.innerHTML;
        opener.insertAtCarret('wiki__text','{{gallery>'+ns+'}}');
        if(!media.keepopen) window.close();
    };

    opts.appendChild(glbl);
    glbl.appendChild(glnk);
    opts.appendChild(gbrk);
}

/**
 * Display a selected page and hide all others
 */
function gallery_pageselect(e){
    var galid = e.target.hash.substr(10,4);

    var pages = getElementsByClass('gallery__'+galid,document,'div');
    for(var i=0; i<pages.length; i++){
        if(pages[i].id == e.target.hash.substr(1)){
            pages[i].style.display = '';
        }else{
            pages[i].style.display = 'none';
        }
    }
    return false;
}

// === main ===
addInitEvent(function() {
    var lightbox = new LightBox({
        loadingimg:DOKU_BASE+'lib/plugins/gallery/images/loading.gif',
        expandimg:DOKU_BASE+'lib/plugins/gallery/images/expand.gif',
        shrinkimg:DOKU_BASE+'lib/plugins/gallery/images/shrink.gif',
        closeimg:DOKU_BASE+'lib/plugins/gallery/images/close.gif',
        nextimg:DOKU_BASE+'lib/plugins/gallery/images/next.gif',
        previmg:DOKU_BASE+'lib/plugins/gallery/images/prev.gif'
    });
    gallery_plugin();

    // hide all pages except the first one
    var pages = getElementsByClass('gallery_page',document,'div');
    for(var i=0; i<pages.length; i++){
        if(!pages[i].id.match(/_1/)){
            pages[i].style.display = 'none';
        }
    }

    // attach page selector
    var pgsel = getElementsByClass('gallery_pgsel',document,'a');
    for(var i=0; i<pgsel.length; i++){
        addEvent(pgsel[i],'click',gallery_pageselect);
    }

});


/* XXXXXXXXXX end of lib/plugins/gallery/script.js XXXXXXXXXX */



/* XXXXXXXXXX begin of lib/plugins/config/script.js XXXXXXXXXX */



/* XXXXXXXXXX end of lib/plugins/config/script.js XXXXXXXXXX */



/* XXXXXXXXXX begin of lib/plugins/description/script.js XXXXXXXXXX */



/* XXXXXXXXXX end of lib/plugins/description/script.js XXXXXXXXXX */



/* XXXXXXXXXX begin of lib/plugins/plugin/script.js XXXXXXXXXX */



/* XXXXXXXXXX end of lib/plugins/plugin/script.js XXXXXXXXXX */



/* XXXXXXXXXX begin of lib/plugins/revert/script.js XXXXXXXXXX */



/* XXXXXXXXXX end of lib/plugins/revert/script.js XXXXXXXXXX */



/* XXXXXXXXXX begin of lib/plugins/slideitmoo/script.js XXXXXXXXXX */



/* XXXXXXXXXX end of lib/plugins/slideitmoo/script.js XXXXXXXXXX */



/* XXXXXXXXXX begin of lib/plugins/imageflow/script.js XXXXXXXXXX */


var imageflow_plugin = function(root) {
	
	var _self = this;
	
	this.root = root;
	
	this.widthfactor = 0.51;
	this.reflectionHeight = 0.5;
	this.bottomLine = this.root.offsetWidth * 0.33; // Or false 

	this.imagesroot = null;
	this.checkedImages = new Array();
	this.imageflowDone = false;

	this.current = 0;
	this.xstep = 150; // pixel to move;
	this.xstepWidthScaleFactor = 0.80; // scale the width of the images  
	this.xstepHeightScaleFactor = 0.60; // scale the height of the images  
	this.focusedElememtsPerSide = 5;

	this.maxheight = this.root.offsetWidth * this.widthfactor;
	this.timeOutAction = null;
	this.whereToMoveQueue = new Array();

	this.images = null;
	this.caption = null;

	// Loader
	this.loadingbar = null;
	this.loadingbartext = null;
	this.loadingbarloader = null;
	
	// Scroller
	this.scrollbarwidth = this.root.offsetWidth * 0.6;
	this.scrollbarSliderOffsetLeft = 38; 
	this.scrollbarSliderOffsetRight = 54;
	this.scrollleft = null;
	this.scrollright = null;
	this.scroller = null;
	
	this.dragStartPosition = false;
	this.scrollerStartDragOffset = false;
	this.scrollerDragOffset = 0;
	this.scrollerIsDragging = false;
	this.scrollerDownIntervall = false;
	this.mouseDownByDrag = false;
	
	this.intermediateImageSrc = DOKU_BASE + 'lib/plugins/imageflow/images/intermediate.png';
	
	this.debug = false;
	
	this.buildBasicStructure = function() {
		
		if ( this.loadingbar !== null || this.images !== null ) { return false; }
		
		var newRoot = document.createElement('div');
		newRoot.className = 'imageflow_root';
		this.root.appendChild(newRoot);
		
		// Start Build Loader
		this.loadingbar = document.createElement('div');
		this.loadingbar.className = 'imageflow_loadingbar_container';
		this.loadingbar.style.top = (this.root.offsetHeight/2 -8) + 'px';
		this.loadingbar.style.left = (this.root.offsetWidth/2 -100) + 'px';
		
		this.loadingbarloader = document.createElement('div');
		this.loadingbarloader.className = 'imageflow_loader';
		
		this.loadingbartext = document.createElement('p');
		this.loadingbartext.appendChild(document.createTextNode('Loading in progress.'));
		
		this.loadingbar.appendChild(this.loadingbarloader);
		this.loadingbar.appendChild(this.loadingbartext);

		newRoot.appendChild(this.loadingbar);
		// End Build Loader

		// Start Build Images Container
		this.images = document.createElement('div');
		this.images.className = 'imageflow_images';
		this.images.style.height = this.root.offsetWidth * 0.338 + 'px';

		newRoot.appendChild(this.images);
		// End Build Images Container

		var splitter = document.createElement('div');
		splitter.className = 'imageflow_no_scroller';
		
		newRoot.appendChild(splitter);
		
		// Start Build Scroller Container
		var scrollbar = document.createElement('div');
		scrollbar.className = 'imageflow_scrollbar';
		scrollbar.style.marginTop = this.root.offsetWidth * 0.02 + 40 + 'px';
		scrollbar.style.width = this.scrollbarwidth + 'px';
		scrollbar.style.left = ((this.root.offsetWidth - (this.scrollbarwidth + this.scrollbarSliderOffsetLeft + this.scrollbarSliderOffsetRight)) / 2) + 'px';

		/* Set slider attributes */
		this.scrollleft = document.createElement('div');
		this.scrollleft.className = 'imageflow_slider_cap_left';
		scrollbar.appendChild(this.scrollleft);

		this.scroller = document.createElement('div');
		this.scroller.className = 'imageflow_slider';
		scrollbar.appendChild(this.scroller);

		this.scrollright = document.createElement('div');
		this.scrollright.className = 'imageflow_slider_cap_right';
		scrollbar.appendChild(this.scrollright);
		
		// AttachEvents
		addEvent(this.scroller, 'mousedown', function(e) { _self.dragStart(e); } );

		addEvent(this.scrollleft, 'mousedown', function(e) { _self.stopEvent(e); _self.scrollerSideDown(-1); } );
		addEvent(this.scrollright, 'mousedown', function(e) { _self.stopEvent(e); _self.scrollerSideDown(1); } );

		addEvent(document, 'mouseup', function(e) { _self.stopEvent(e); _self.scrollerSideUp(); } );
		addEvent(scrollbar, 'click', function(e) { _self.scrollerClick(e); } );
		
		newRoot.appendChild(scrollbar);
		// End Build Scroller Container
		
		// Start Build Caption Container
		this.caption = document.createElement('div');
		this.caption.className = 'imageflow_caption';
		this.caption.style.width = (this.root.offsetWidth * 0.5) + 'px';
		this.caption.style.left = (this.root.offsetWidth * 0.25) + 'px';
		this.caption.style.marginTop = this.root.offsetWidth * 0.02 + 'px';

		newRoot.appendChild(this.caption);
		// End Build Caption Container
		
		if ( !this.debug ) { return; } 
		// Add Debug
		this.debug = document.createElement('div');
		this.debug.className = 'debug';
		
		this.debug.appendChild(document.createTextNode('Debug is enabled.'));
		
		newRoot.appendChild(this.debug);
	};
	
	this.stopEvent = function(event) {
		event = event||window.event;
		
		if (event) {
			event.cancelBubble = true;
			event.returnValue = false;
			if (event.stopPropagation) { event.stopPropagation(); }
			if (event.preventDefault) { event.preventDefault(); }
		}
	};
	
	this.loadImageEvent = function (src, eventFkt) {
		var loadImage = new Image();
		addEvent(loadImage, 'load', eventFkt);
		loadImage.src = src;
	};
	
	// Set Timeout for clusores
	this.timeOut = function(fkt, time) {
		setTimeout(function(e) { _self[fkt](e, this); }, time);
	};
	
	this.init = function() {
		
		this.root.className += " scripting_active";
		this.root.innerHTML = "";
		this.root.style.height = (this.maxheight + 20) + 'px';
		this.buildBasicStructure();
		
		// Loader Image Cascade
		// Prepare Loader images - they have to be shown very first.
		var loadImage = new Image();
		addEvent(loadImage, 'load', function() {

			_self.loadingbar.style.display = 'block'; // Show loader Bar
			var loadImage = new Image();
			addEvent(loadImage, 'load', function() {
				_self.timeOut('initImages', 500);
			});
			
			loadImage.src = DOKU_BASE + 'lib/plugins/imageflow/images/loader_bg.gif';
		});
		
		loadImage.src = DOKU_BASE + 'lib/plugins/imageflow/images/loader.gif';
		
		var intermediate = new Image();
		intermediate.src = this.intermediateImageSrc;

	};
	
	this.initImages = function () {
		
		try {
			// get images from JSINFO var
			this.imagesroot = JSINFO['relation']['imageflow'][this.root.id];

			for ( var i in this.imagesroot ) {
				
				var imgData = this.imagesroot[i];
				if ( typeof imgData == 'undefined' ) { continue; }
				
				var imgRep = new imageRepresentation();
				imgRep.init(imgData);
				
				this.checkedImages.push(imgRep);
			}
			
			this.timeOut('checkForImagesReady', 50);
		} catch(e) {}
	};
	
	/*
	 * END OF ALL INIT THINGS
	 */
	
	
	/*
	 * Represents an image with special functions inside
	 */
	var imageRepresentation = function() {
		
		var __self = this;
		
		this.imgData = null;
		this.image = null;
		this.id = null;
		
		this.counter = 300;
		this.isFinished = false;
		
		this.x_pos = 0;
		this.width = 0;
		this.height = 0;
		this.pc = 0;
		
		this.isImageOk = function(img) {
			
			if ( !img ) { img = this.image };
			if (!img.complete) { return false; }
			if (typeof img.naturalWidth != "undefined" && img.naturalWidth == 0) { return false; }

			// No Way to determine
			return true;
		};
		
		this.intermediateFinish = function() {
			
			this.counter = 10;
			this.imgData.intermediateImage = this.image;
			this.image = new Image();

			this.imgData.intermediateImage.onload = function(e) {

				// reset the image
				__self.image.parentNode.replaceChild(__self.imgData.intermediateImage, __self.image);
				__self.image = __self.imgData.intermediateImage;
				__self.finish();
				
				_self.moveTo(_self.current); // Force repaint
			};
			
			addEvent(this.image, 'load', function(e) { __self.finish(); });
			this.image.src = _self.intermediateImageSrc;
		};
		
		this.finish = function() {
			
			this.counter = 0; 
			this.width = this.image.width;
			this.height = this.image.height; // - ( this.image.height * this.reflectionHeight ); // Height w/o reflection

			/* Check source image format. Get image height minus reflection height! */
			this.pc = _self.xstep * (((this.width + 1) > (this.height / (_self.reflectionHeight + 1))) ? _self.xstepWidthScaleFactor : _self.xstepHeightScaleFactor);
		};
		
		this.checkFinished = function() {
			var isOK = this.isImageOk();
			if ( !isOK && this.counter > 0 ) {
				this.counter--;
				return false;
			} else if ( !isOK && this.counter == 0) {
				this.intermediateFinish();
			}
			
			this.isFinished = true;
			this.finish();
			return true;
		};
		
		this.init = function(imgData) {
			
			this.imgData = imgData;
			this.imgData.isImage = true;
			
			this.image = new Image();
			var src = this.imgData.src;
			if ( imgData.params ) {
				for ( var key in imgData.params) {
					src += (src.indexOf('?') > 0 ? '&' : '?') + escape(key) + "=" + escape(imgData.params[key]);
				}
			}
			
			this.image.src = src;
			this.image.id = this.imgData.id;
			this.id = this.imgData.id;
			this.image.style.display = 'none';

			addEvent(this.image, 'load', function() { __self.finish(); });
		}
	};	
	
	this.loadingStatus = function() {
		
		var completed = 0; var total = 0;
		
		for ( var img in this.checkedImages ) {
			if ( this.checkedImages[img].isFinished || this.checkedImages[img].checkFinished() ) { completed++; }
			total ++;
		}

		var finished = Math.round((completed/total)*100);
		if ( finished >= 100 ) { finished = 100; }
		
		this.loadingbarloader.style.width = finished+'%';
		this.loadingbar.style.display = 'block';

		var loadingTxt = document.createTextNode('Loading Images ' + completed + '/' + total);
		this.loadingbartext.replaceChild(loadingTxt,this.loadingbartext.firstChild);

		return finished;
	};
	
	this.checkForImagesReady = function() {
		
		if ( this.imageflowDone ) { return; }
		if ( this.loadingStatus() < 100 ) {
			this.timeOut('checkForImagesReady', 50);
			return;
		} else {
			this.imageflowDone = true;
		}
		
		this.refreshImageFlow();
		this.addGlobalEvents();
		this.checkForPopUp();
	};
	
	this.addGlobalEvents = function () {
		/** DOMMouseScroll is for mozilla. */
		if (window.addEventListener) {
	        window.addEventListener('DOMMouseScroll', function(e) { _self.globalEvent(e); }, false);
		}
		addEvent(this.root, 'mousewheel', function(e) { _self.globalEvent(e); });
		addEvent(document, 'keydown', function(e) { _self.globalEvent(e); });
		addEvent(this.root, 'mousemove', function(e) { _self.drag(e); } );

		addEvent(document, 'mouseup', function(e) { _self.dragStop(e); } );
		addEvent(this.root, 'selectstart', function (e) { _self.dragStop(e); } );
		
	};
	
	/*
	 * BEGINN OF ALL MOVEMENT THINGS
	 */
	this.refreshImageFlow = function() {
		
		var img = 0;
		for ( img; img < this.checkedImages.length; img++ ) {
			var imageElement = this.checkedImages[img];

			this.images.appendChild(imageElement.image);

			imageElement.image.style.display = 'block';
			imageElement.image.style.cursor = 'pointer';

			imageElement.image.onclick = function(e) { _self.elementClick(e); };
			imageElement.image.ondblclick = function(e) { _self.specialClick(e); };
			
			addEvent(imageElement.image, 'mousedown', function(e) { _self.dragStart(e); } );
		}

		if ( img <= 1 ) {
			var loadingTxt = document.createTextNode('Ups. There are no Images.');
			this.loadingbartext.replaceChild(loadingTxt,this.loadingbartext.firstChild);
			this.loadingbartext.style.color = "#a00";
			
			return;
		}
		
		this.loadingbar.style.display = 'none';
		this.scroller.parentNode.style.visibility = 'visible';
		this.moveTo(this.current, this.current);
		this.glideTo(this.current);
	};
	
	this.moveTo = function(whereToMove, origWhereToMoveIndex) {
		
		//this.current = whereToMove;
		var zIndex = this.checkedImages.length;
		var size = this.root.offsetWidth * 0.5;
		var images_top = 50; // Offset from top
		
		for ( var img in this.checkedImages ) {
			var imageElement = this.checkedImages[img];
			
			// Hide Elements outside of our viewport
			if ( img < this.current - this.focusedElememtsPerSide || img > this.current + this.focusedElememtsPerSide ) {
				imageElement.image.style.display = 'none';
				imageElement.image.style.visiblity = 'hidden';
				continue;
			}
			
			var movement = (img - this.current) * this.xstep;
			var z = Math.sqrt(10000 + movement * movement) + 100;
			var xs = movement / z * size + size;

			/* Still hide images until they are processed, but set display style to block */
			imageElement.image.style.display = 'block';
			
			/* Process new image height and image width */
			var new_img_h = (imageElement.height / imageElement.width * imageElement.pc) / z * size;
			var new_img_w = imageElement.pc / z * size;
			
			if ( new_img_h > this.maxheight ) {
				new_img_h = this.maxheight;
				new_img_w = imageElement.width * new_img_h / imageElement.height;
			}
			
			var new_img_top = ((new_img_h / (this.reflectionHeight + 1)) * this.reflectionHeight);
			if ( this.bottomLine !== false ) { new_img_top += (this.bottomLine - new_img_h); }
			
			imageElement.image.style.left = xs - (imageElement.pc / 2) / z * size + 'px';

			if(new_img_w && new_img_h)
			{ 
				imageElement.image.style.height = new_img_h + 'px'; 
				imageElement.image.style.width = new_img_w + 'px'; 
				imageElement.image.style.top = new_img_top + 'px';
			}
			
			imageElement.image.style.visibility = 'visible';
			
			/* Set image layer through zIndex */
			if ((img - this.current) < 0) {
				zIndex++;
			} else {
				zIndex--;
			}
			
			// register new handles
			if ( img == origWhereToMoveIndex ) {
				zIndex++;

				imageElement.image.onclick = function(e) { _self.specialClick(e); };
			} else {
				imageElement.image.onclick = function(e) { _self.elementClick(e); };
			}
			
			imageElement.image.style.zIndex = zIndex;
		}
		
		this.current = whereToMove;
		
		// Set Caption, though its not performaing best here
		if (this.checkedImages[origWhereToMoveIndex]) { this.buildCaptionForElement(this.checkedImages[origWhereToMoveIndex].imgData); }
		this.setSliderPosition();
	};
	
	this.buildCaptionForElement = function(imgData) {

		// Remove old Caption
		this.caption.innerHTML = "";

		// Create new Caption if title or caption given
		if ( imgData.title ) {
			var title = document.createElement('h3');
			title.appendChild(document.createTextNode(imgData.title));
			this.caption.appendChild(title);
		}
		
		if ( imgData.desc ) {
			var caption = document.createElement('p');
			caption.appendChild(document.createTextNode(imgData.desc));
			this.caption.appendChild(caption);
		}
	};
	
	this.setSliderPosition = function(override) {
		var new_slider_pos = (this.scrollbarwidth * (this.current/(this.checkedImages.length-1)));
		if ( new_slider_pos >= 0 &&  new_slider_pos <= this.scrollbarwidth && ( this.scrollerStartDragOffset === false || override === true ) ) {
			this.scroller.style.marginLeft = new_slider_pos - (this.scroller.offsetWidth / 2) + 'px';
		}
	};
	
	this.glideTo = function(whereToMove) {

		if ( whereToMove < 0 ) { whereToMove = 0; }
		if ( whereToMove >= this.checkedImages.length ) { whereToMove = this.checkedImages.length-1; }
		
		// Animate gliding to new position
		// If current position is not the desired one
		var devident = (this.whereToMoveQueue.length > 1 ? 1 : this.xstep); // check distance
		if ( whereToMove < this.current - 1/devident || whereToMove > this.current + 1/devident ) 
		{
			this.moveTo(this.current + (whereToMove-this.current)/3, whereToMove); // move in three steps
			this.timeOutAction = setTimeout(function(){ _self.glideTo(whereToMove) }, 50);
			return;
		}
		
		this.current = whereToMove;

		if ( this.whereToMoveQueue.length > 1 ) { // Asume, the first entry is the first moving step
			this.timeOutAction = setTimeout(function() {
				_self.glideTo(parseInt(_self.whereToMoveQueue.splice(1,1))); }, 50);
		} else {

			// Display new caption
			this.moveTo(this.current, this.current); // If the above got interrupted, set the new distance

			this.timeOutAction = null; // Reset Timeout
			_self.whereToMoveQueue = new Array();
		}
	};
	
	this.addMoveElementToQueue = function (whereToMove) {
		if ( whereToMove < 0 ) { whereToMove = 0; } // Already the first
		if ( whereToMove >= this.checkedImages.length ) { whereToMove = this.checkedImages.length-1; } // This is already the last

		this.whereToMoveQueue.push(whereToMove);
		this.glideTo(whereToMove);

		return true;
	};
	
	this.handle = function(delta) {

		var whereToMove = this.current;
		if ( this.timeOutAction ) {
			clearTimeout(this.timeOutAction);
			this.timeOutAction = null;
			whereToMove = parseInt(this.whereToMoveQueue[this.whereToMoveQueue.length - 1]);
			this.whereToMoveQueue = new Array();
		}
		
		whereToMove += delta;
		if ( this.addMoveElementToQueue(whereToMove) ) { return whereToMove; }
	};
	
	this.drag = function(e) {
	
		e = e ||window.event;
		if ( !this.dragStartPosition ) { return; } // Dragging not inited

		var direction = this.scrollerIsDragging ? 1 : -1;
		var posx = document.all ? window.event.clientX : e.pageX;
		var move =  direction * (posx - this.dragStartPosition);

		this.stopEvent(e);
		this.debug.innerHTML = "Draging " + ((e.target) ? e.target : e.srcElement).id;
		
		if ( !this.scrollerIsDragging ) { // Dragging at the image

			this.debug.innerHTML += " dragging image";
			
			if ( this.scrollerStartDragOffset === false || isNaN(this.scrollerStartDragOffset.target) || isNaN(this.scrollerStartDragOffset.current) ) {
				this.scrollerStartDragOffset = {};
				this.scrollerStartDragOffset.target = this.getClickImage(e);
				this.scrollerStartDragOffset.current = this.current;
				
				this.debug.innerHTML += " setting StartDragOffset (" + this.scrollerStartDragOffset.target + " / " + this.scrollerStartDragOffset.current + ")";
			}
			
			var s = this.images.offsetWidth/2;
			var movement = (this.scrollerStartDragOffset.target - this.scrollerStartDragOffset.current) * this.xstep;
			var z = Math.sqrt(10000 + movement * movement) + 100;
			var xs = movement / z * s;

			this.debug.innerHTML += " move1: " + move;
			move += direction * (xs);
			this.debug.innerHTML += " move2: " + move;
			
			xs = move + s;
			if ( xs < 0 ) { xs = 0; }
			if ( xs > 2*s ) { xs = 2*s - 1; }
			movement = (200 * s * ( xs -s ) / ( (2*s - xs) * xs )) / this.xstep;
			this.debug.innerHTML += " movement1: " + movement;
			this.debug.innerHTML += " xs: " + xs;

			// Maximum movement to either side
			if ( movement > this.focusedElememtsPerSide ) { movement = this.focusedElememtsPerSide; } 
			if ( movement < -this.focusedElememtsPerSide ) { movement = -this.focusedElememtsPerSide; }
			
			movement += this.scrollerStartDragOffset.current + (this.scrollerStartDragOffset.target - this.scrollerStartDragOffset.current);
			
			this.debug.innerHTML += " movement2: " + movement;
			this.moveTo(movement, Math.round(movement));
			this.setSliderPosition(true);
			this.mouseDownByDrag = true;

			
			// this.debug.innerHTML = movement + " " + this.current;
			
		} else {
			this.debug.innerHTML += " dragging scroller";

			var deltaPercent = move * 100 / this.scrollbarwidth;
			var delta = Math.round(this.checkedImages.length / 100 * deltaPercent);

			if ( this.scrollerStartDragOffset !== false ) {
				var new_slider_pos = this.scrollerStartDragOffset - (direction * this.dragStartPosition) + (direction * posx);
				if ( new_slider_pos < 0 ) { new_slider_pos = 0; }
				if ( new_slider_pos > this.scrollbarwidth ) { new_slider_pos = this.scrollbarwidth ; }
				this.scroller.style.marginLeft = new_slider_pos - (this.scroller.offsetWidth / 2) + 'px';
			}

			if (this.scrollerDragOffset - delta != 0) {
				this.handle(delta - this.scrollerDragOffset);
				this.scrollerDragOffset = delta;
			}
		}

	};

	this.dragStart = function(e) {

		e = e||window.event;
		
		this.debug.innerHTML = "Drag Start " + ((e.target) ? e.target : e.srcElement).id;
		if ( this.timeOutAction !== null ) { return; }
		
		this.dragStartPosition = document.all ? e.clientX : e.pageX;
		this.scrollerIsDragging = ((e.target) ? e.target : e.srcElement) == this.scroller;
		this.scrollerStartDragOffset = this.scrollerIsDragging ? this.scroller.offsetLeft : false;
		this.stopEvent(e);
	};
	
	this.dragStop = function(e) {
		
		e = e||window.event;
		this.debug.innerHTML = "Drag Stop " + ((e.target) ? e.target : e.srcElement).id;

		if ( this.dragStartPosition === false ) { return; } 
		this.stopEvent(e);

		if ( this.scrollerIsDragging === false && typeof this.scrollerStartDragOffset == 'object' && isFinite(parseInt(this.scrollerStartDragOffset.target)) ) {
			// Snap to Element
			this.addMoveElementToQueue(Math.round(this.current));
		}

		this.dragStartPosition = false;
		this.scrollerStartDragOffset = false;
		this.scrollerIsDragging = false;
		this.scrollerDragOffset = 0;
		this.setSliderPosition();
		setTimeout( function() { _self.mouseDownByDrag = false; }, 100);
	};
	
	this.scrollerClick = function(e) {

		e = e ||window.event;
		this.stopEvent(e);
		
		if ( this.mouseDownByDrag ) { return; }
		if ( ((e.target) ? e.target : e.srcElement) != this.scroller.parentNode) { return; }
		this.debug.innerHTML = "Scroller Click " + ((e.target) ? e.target : e.srcElement).id;
		
		this.mouseDownByDrag = true;
		
		this.dragStartPosition = findPosX(this.scroller) + this.scroller.offsetWidth/2;
		this.scrollerStartDragOffset = false;
		this.scrollerIsDragging = true;
		
		this.drag(e);
		this.dragStop(e);
		this.mouseDownByDrag = false;

		
	};
	
	this.scrollerSideDown = function(direction) {
		if ( this.scrollerDownIntervall !== false ) { return; }
		this.debug.innerHTML = "Side Down";

		this.handle(direction);
		this.scrollerDownIntervall = window.setInterval( function() { _self.handle(direction); }, 500);
	};
	
	this.scrollerSideUp = function() {
		if ( this.scrollerDownIntervall === false ) { return; }
		this.debug.innerHTML = "Side Up";

		window.clearInterval(this.scrollerDownIntervall);
		this.scrollerDownIntervall = false;
	};
	
	this.specialClick = function(e) {

		e=e||window.event;
		if ( this.mouseDownByDrag ) { return; }

		this.stopEvent(e);
		this.debug.innerHTML = "Special Click";

		// If we have the popupviewer, lets do some action!
		if ( typeof popupviewer == 'undefined' ) {
			return;
		}
		
		if ( (whereToMove = this.getClickImage(e)) === false ) { return; }
		
		var viewer = new popupviewer();

		// Overwrite function
		viewer.skipToImage = function(itemNr) {

			var didMoveTo = _self.handle(itemNr);
			if ( didMoveTo === false ) { return; }
			
			var imageElement = _self.checkedImages[didMoveTo];

			imageElement.image.onclick = function(e) { _self.specialClick(e); };

			if (imageElement.image) {
				this.dispatchClick(imageElement.image);
			}
		};
		
		viewer.popupImageStack = this.checkedImages;
		var linkTo = this.checkedImages[whereToMove].imgData.linkto || this.checkedImages[whereToMove].imgData;
			
		viewer.init(e);
		if ( linkTo.isImage === true ) {
			viewer.displayContent(linkTo.src, true);
		} else {
			viewer.loadAndDisplayPage(linkTo.src, linkTo.width, linkTo.height, null, linkTo.params);
			viewer.page = this.checkedImages[whereToMove].id;
		}
	};
	
	this.elementClick = function(e) {
		e = e||window.event;

		if ( this.mouseDownByDrag ) { return; }
		if ( (whereToMove = this.getClickImage(e)) === false ) { return; }
		this.debug.innerHTML = "Element Click " + ((e.target) ? e.target : e.srcElement).id;
		
		this.stopEvent(e);

		if ( this.timeOutAction ) {
			clearTimeout(this.timeOutAction);
			this.timeOutAction = null;
			this.whereToMoveQueue = new Array();
		}
		
		this.addMoveElementToQueue(whereToMove);
	};
	
	this.getClickImage = function(e) {
		e = e||window.event;
		
		var target = ((e.target) ? e.target : e.srcElement);
		this.debug.innerHTML = "Click " + target.id;

		var whereToMove = 0;
		while ( target != this.checkedImages[whereToMove].image ) {
			whereToMove++;
		}
		
		if ( whereToMove >= this.checkedImages.length ) { return false; }
		return whereToMove;
	};
	
	this.checkForPopUp = function() {
		if ( document.location.href.indexOf('#') == 0 ) { return; }
		var extend = document.location.href.substr(document.location.href.indexOf('#')+1);
		if ( typeof extend == "undefined" || !$(extend) ) { return; }

		var e = {};
		e.target = $(extend);
		this.elementClick(e);
		this.specialClick(e);
	};
	
	this.globalEvent = function(e) {
		
		e = e||window.event;
		
		var delta = false;
		
		if (e.keyCode) {
			switch (e.keyCode) {
			/* Right arrow key */
			case 39:
				delta = 1;
				break;

			/* Left arrow key */
			case 37:
				delta = -1;
				break;
			}
		} else if (e.wheelDelta) {
			delta = -e.wheelDelta;
		} else if (e.detail) { // Mozilla Handling

			var target = ((e.target) ? e.target : e.srcElement);
			var nodes = this.root.getElementsByTagName(target.nodeName);
			for ( var elem in nodes ) {
				if ( nodes[elem] == target ) {
					delta = e.detail;
					break;
				}
			}
		}
		
		if ( delta ) {
			this.stopEvent(e);
			this.handle(delta  > 0 ? 1 : -1);
		}
	};
	
	this.init();
};


addInitEvent(function() {
		var imageflow = getElementsByClass('imageflow_wrapper', document, 'div');
		for ( var flow in imageflow ) {
			var imgF = new imageflow_plugin(imageflow[flow]);
		}
});


/* XXXXXXXXXX end of lib/plugins/imageflow/script.js XXXXXXXXXX */



/* XXXXXXXXXX begin of lib/plugins/usermanager/script.js XXXXXXXXXX */

/**
 * Add JavaScript confirmation to the User Delete button
 */
function usrmgr_delconfirm(){
    if($('usrmgr__del')){
        addEvent( $('usrmgr__del'),'click',function(){ return confirm(reallyDel); } );
    }
};
addInitEvent(usrmgr_delconfirm);


/* XXXXXXXXXX end of lib/plugins/usermanager/script.js XXXXXXXXXX */



/* XXXXXXXXXX begin of lib/plugins/alphaindex/script.js XXXXXXXXXX */



/* XXXXXXXXXX end of lib/plugins/alphaindex/script.js XXXXXXXXXX */



/* XXXXXXXXXX begin of lib/plugins/popularity/script.js XXXXXXXXXX */



/* XXXXXXXXXX end of lib/plugins/popularity/script.js XXXXXXXXXX */



/* XXXXXXXXXX begin of lib/plugins/reflect/script.js XXXXXXXXXX */



/* XXXXXXXXXX end of lib/plugins/reflect/script.js XXXXXXXXXX */



/* XXXXXXXXXX begin of lib/plugins/popupviewer/script.js XXXXXXXXXX */

var popupviewer = function(showContent, isImage, width, height) {

	this.screenWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
	this.screenHeight = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
	this.contentDiv = null;
	this.controlDiv = null;
	this.maxWidthFactor = 0.7;
	this.maxHeightFactor = 0.8;
	this.maxWidth = null;
	this.maxHeight = null;
	this.endWidth = 0;
	this.endHeight = 0;
	this.endMarginTop = 0;
	this.endMarginLeft = 0;
	this.isImage = false;
	this.additionalContent = null;
	this.additionalContentID = null;
	this.page = null;
	this.event = null;
	this.wasError = false;
	this.popupImageStack = null;

	this.showContent = null;
	this.isRTL = false;

	this.getFirst = function() { /* To be implemented */
		if (!this.popupImageStack) {
			return false;
		}
		return this.popupImageStack[0].id == this.page;
	};

	this.getLast = function() { /* To be implemented */
		if (!this.popupImageStack) {
			return false;
		}
		return this.popupImageStack[this.popupImageStack.length - 1].id == this.page;
	};

	this.skipToImage = function(itemNr) {

		var previous = null;
		var elem = null;
		for ( var item in this.popupImageStack) {

			var check = this.popupImageStack[item];
			
			// previous was inpoint
			if (previous && previous.id == this.page) {
				elem = check;
				break;
			}

			// Found + must go
			if (check.id == this.page && itemNr < 0) {
				elem = previous;
				break;
			}

			previous = check;
			elem = check;
		}

		if (elem) {
			this.dispatchClick(elem);
		}
	};
	
	this.dispatchClick = function(elem) {
		if (elem == null) {
			return;
		}

		if (document.createEventObject) {
			// dispatch for IE
			var evt = document.createEventObject();
			return elem.fireEvent('onclick', evt)
		} else {
			// dispatch for firefox + others
			var evt = document.createEvent("HTMLEvents");
			evt.initEvent('click', true, true); // event
												// type,bubbling,cancelable
			return !elem.dispatchEvent(evt);
		}
	};

	this.setContentSize = function(width, height, offsetHeight) {

		if (!this.contentDiv || !this.controlDiv) {
			return;
		}

		if (!width || width === 0) {
			width = this.screenWidth * this.maxWidthFactor;
		}

		if (!height || height === 0) {
			height = this.screenHeight * this.maxHeightFactor;
		}

		width = parseFloat(width);
		height = parseFloat(height);
		offsetHeight = typeof offsetHeight == "undefined" || isNaN(parseFloat(offsetHeight)) ? 0 : parseFloat(offsetHeight); // may be undefined
		var ratio = width / height;

		height += offsetHeight;

		if (height > (this.screenHeight * 0.99) - 60) {
			height = (this.screenHeight * 0.99) - 60;

			if (this.isImage) { // If this is an image we will have to fix the size
				width = (height - offsetHeight) * ratio;
			} else {
				width += 20; // For the scroller Bar that will apear;
			}
		}

		if (width > (this.screenWidth * 0.99) - 40) {
			width = (this.screenWidth * 0.99) - 40;

			if (this.isImage) { // If Image is defined then we will have to fix it
				height = (height / ratio) + offsetHeight;
			}
		}

		this.endWidth = width + (this.isImage ? 0 : 24); // 24 Px for padding + Border if is Image
		this.endHeight = height;

		var xOffset = document.body.scrollLeft || document.documentElement.scrollLeft || window.pageXOffset || 0;
		var yOffset = document.body.scrollTop || document.documentElement.scrollTop || window.pageYOffset || 0;

		this.endMarginTop = (this.screenHeight - height) * 0.5 + yOffset;
		if (this.endMarginTop < 5) {
			this.endMarginTop = 5;
		}

		this.endMarginLeft = (this.screenWidth - width) * 0.5 + xOffset;
		this.setSize();
		this.addNextAndPrevious();
	};

	this.setSize = function() {

		var style = "width:" + this.endWidth + 'px;';
		if (!this.isImage) {
			style += "height:" + this.endHeight + 'px;';
		}

		this.contentDiv.style.cssText = style; // Really nasty IE6 hacking!
		this.contentDiv.setAttribute('style', style);

		style = "top:" + this.endMarginTop + 'px;';

		if (!this.isRTL) {
			style += "left:" + this.endMarginLeft + 'px;';
		} else {
			style += "right:" + this.endMarginLeft + 'px;';
		}

		this.controlDiv.style.cssText = style; // Really nasty IE6 hacking!
		this.controlDiv.setAttribute('style', style);
	};

	this.addNextAndPrevious = function() {

		// If not already defined, do so now
		if (!this.popupImageStack) {
			this.popupImageStack = getElementsByClass('popupimage', document, 'img');
		}

		if (this.popupImageStack && this.popupImageStack.length > 1) {

			var previousImage = document.createElement('a');
			previousImage.id = 'popupviewer_control_prevoiusImage';

			var nextImage = document.createElement('a');
			nextImage.id = 'popupviewer_control_nextImage';

			var self = this;
			var skipEvent = function(event) { /* To be implemented */

				if (!event) {
					var event = window.event;
				}

				var target = ((event.target) ? event.target : event.srcElement).id.indexOf("next") > 0 ? 1 : -1;
				self.skipToImage(target);
			};

			// If this is not the last image - set inactive
			if (!this.getLast()) {
				addEvent(nextImage, 'click', skipEvent);
			} else {
				nextImage.className = "inactive";
			}

			// If this is not the first image - set inactive
			if (!this.getFirst()) {
				addEvent(previousImage, 'click', skipEvent);
			} else {
				previousImage.className = "inactive";
			}

			this.controlDiv.appendChild(nextImage);
			this.controlDiv.appendChild(previousImage);
		}
	};

	this.getIntValue = function(value) {
		return parseInt(value.substr(0, value.indexOf('px')), 10);
	};

	this.buildViewerWithLoader = function() {

		this.removeOldViewer();
		this.contentDiv = document.createElement('div');
		this.contentDiv.id = 'popupviewer_content';
		this.contentDiv.className = 'isImage';

		this.controlDiv = document.createElement('div');
		this.controlDiv.id = 'popupviewer_control';

		this.controlDiv.appendChild(this.contentDiv);

		var loaderDiv = document.createElement('div');
		loaderDiv.id = 'popupviewer_loader_div';

		this.contentDiv.appendChild(loaderDiv);

		var closeImage = document.createElement('a');
		closeImage.id = 'popupviewer_control_closeImage';

		this.controlDiv.appendChild(closeImage);

		var sampleDiv = document.createElement('div');
		sampleDiv.id = 'popupviewer';

		var overlayDiv = document.createElement('div');
		overlayDiv.id = 'popupviewer_overlay';

		var arVersion = navigator.appVersion.split("MSIE");
		var version = parseFloat(arVersion[1]);
		if (!(version >= 5.0 && version < 7.0)) {
			overlayDiv.style.position = 'fixed';
		} else {
			overlayDiv.style.height = (document.body.offsetHeight -1 ) + 'px';
			overlayDiv.style.width = (document.body.offsetWidth -1 ) + 'px';
		}

		sampleDiv.appendChild(overlayDiv);

		/* IE 6 Crasher */
		sampleDiv.appendChild(this.controlDiv);

		addEvent(overlayDiv, 'click', function() {
			if ($('popupviewer')) {
				$('popupviewer').parentNode.removeChild($('popupviewer'));
			}
			document.getElementsByTagName('body')[0].style.overflow = 'auto';
		});
		addEvent(closeImage, 'click', function() {
			if ($('popupviewer')) {
				$('popupviewer').parentNode.removeChild($('popupviewer'));
			}
			document.getElementsByTagName('body')[0].style.overflow = 'auto';
		});

		// window.scrollTo(0, 0);
		document.getElementsByTagName('body')[0].style.overflow = 'hidden';
		document.getElementsByTagName('body')[0].appendChild(sampleDiv);

		this.setContentSize(210, 20);
	};

	this.removeOldViewer = function() {
		if ($('popupviewer')) {
			$('popupviewer').parentNode.removeChild($('popupviewer'));
		}
	};

	this.displayContent = function(showContent, isImage, width, height) {

		this.isImage = isImage;

		if (!$('popupviewer')) {
			this.buildViewerWithLoader();
		}
		if (!showContent || showContent === null) {
			if (typeof (showContent) != 'undefined') {
				this.setContentSize(width, height, true);
			}
			return this;
		}

		if (isImage) {

			var img = new Image();
			img.src = showContent;
			img.className = "imageContent";

			if (this.event) {
				var elem = (this.event.target) ? this.event.target : this.event.srcElement;
				this.page = elem.id;
			}

			var check = new checkImageRoutine(img);
			var self = this;
			var callback = {

				image : img,
				error : function() {
					self.removeOldViewer();
				},
				finalize : function() {

					// var height = this.image.height;
					var selfCallback = this;

					// self.setContentSize(this.image.width, height, true);
					var callback = function(response) {

						var container = document.createElement('div');
						container.className = 'additionalContent dokuwiki';
						container.innerHTML = response;

						$('popupviewer_content').appendChild(selfCallback.image);
						$('popupviewer_content').removeChild($('popupviewer_loader_div'));
						self.contentDiv.className = 'dokuwiki';
						self.contentDiv.className = 'isImage';
						$('popupviewer_content').appendChild(container);

						self.setContentSize(selfCallback.image.offsetWidth,selfCallback.image.offsetHeight,container.offsetHeight);
						var style = 'width:' + self.endWidth + 'px; height:' + self.endHeight + 'px;';
						selfCallback.image.style.cssText = style; // Really nasty IE6 hacking!
						selfCallback.image.setAttribute('style', style);
					};

					var errorCallback = function() {
						$('popupviewer_content').appendChild(selfCallback.image);
						$('popupviewer_content').removeChild($('popupviewer_loader_div'));
						self.contentDiv.className = 'dokuwiki';
						self.contentDiv.className = 'isImage';

						self.setContentSize(selfCallback.image.offsetWidth, selfCallback.image.offsetHeight);
						var style = 'width:' + self.endWidth + 'px; height:' + self.endHeight + 'px;';
						selfCallback.image.style.cssText = style; // Really
																	// nasty IE6
																	// hacking!
						selfCallback.image.setAttribute('style', style);

					};

					if (self.additionalContent) {
						callback(self.additionalContent);
					} else {
						self.runAJAX(callback, {
							'call' : '_popup_load_image_meta',
							'id' : self.additionalContentID
						}, errorCallback);
					}

				}
			};

			check.checkLoadImage(50, callback);
		} else {
			this.contentDiv.className = 'dokuwiki';
			this.contentDiv.innerHTML = showContent;
			this.setContentSize(width, height, true);
		}
	};

	this.linkReplacer = function(matches, depth) {

		var schema = matches[1];
		var urlpart = matches[2];

		if (urlpart.match(/^#(.*?)$/)) {
			// ScrollToDiv
			urlpart += "\" onclick=\"if(!event){var event=window.event;}if(event){event.cancelBubble=true;event.returnValue=false;}if(event&&event.stopPropagation){event.stopPropagation();}if(event&&event.preventDefault){event.preventDefault();}$('popupviewer_content').scrollTop=$('"
					+ ((urlpart == "#") ? "popupviewer_content" : urlpart
							.substr(1)) + "').offsetTop;return false;";
		} else if (!urlpart.match(new RegExp("^(https?:\/\/|mailto:|"
				+ escape(DOKU_BASE) + ")"))) {
			urlpart = depth + urlpart;
		}

		return schema + '="' + urlpart + '"';
	};

	this.loadAndDisplayPage = function(page, width, height, id, params) {

		if (this.event) {
			var elem = (this.event.target) ? this.event.target : this.event.srcElement;
			this.page = elem.href == page ? elem.getAttribute('href') : "";
		}

		this.endWidth = width;
		this.endHeight = height;

		var self = this;
		var callback = function(data) {

			/* Reset Init Events */
			window.oninit = function() {
			};

			/* check for script to be executed */
			var script = "";
			if (typeof data == "string" && data !== '') {
				data = data.replace(/<script[^>]*>([\s\S]*?)<\/script>/gi,
						function() {
							if (data !== null) {
								script += arguments[1] + '\n';
							}
							return '';
						});
			}

			try {
				data = self.preg_replace_callback(
						'/(href|src|action)="([^"]*)"/ig', self.linkReplacer,
						data);
				self.displayContent(data, false, self.endWidth, self.endHeight);
			} catch (e) {
				alert(e);
				return self.removeOldViewer();
			}
			try {
				eval(script + "window.oninit();");
			} catch (scriptE) {
			}
		};

		var errorCallback = function(ajax) {

			var id = "errorCallbackForm";
			if ($(id)) {
				$(id).parentNode.removeChild($(id));
			}
			var form = document.createElement("form");
			form.setAttribute("action", page);
			form.setAttribute("method", "POST");
			form.id = id;
			ajax.requestFile = page;
			self.wasError = true;

			document.getElementsByTagName("body")[0].appendChild(form);

			// Create Compl.etion function
			ajax.onCompletion = function() {

				if (ajax.responseXML) {
					var dwEle = getElementsByClass('dokuwiki',
							ajax.responseXML, 'div');
					if (dwEle.length > 0) {
						ajax.response = '<div class="dokuwiki">'
								+ dwEle[0].innerHTML + "</div>";
					}
				}

				callback(ajax.response);
				if (typeof ajax.execute == "object" && ajax.execute.srcForm
						&& $(ajax.execute.srcForm.id)) {
					$(ajax.execute.srcForm.id).parentNode
							.removeChild($(ajax.execute.srcForm.id));
				}
			};

			// call via proxy
			var proxy = new iframeProxy(ajax, form);
		};

		// Set custom params
		if ( (typeof params).toLowerCase() != "object" ) { params = {}; }
		if ( !params.call ) { params.call = '_popup_load_file'; }
		if ( !params.id ) { params.id = id; }
		this.runAJAX(callback, params, errorCallback);
	};

	this.runAJAX = function(callback, options, errorCallback, url) {

		if (typeof url == "undefined") {
			url = DOKU_BASE + 'lib/exe/ajax.php';
		}

		ajax = new sack(url);
		ajax.AjaxFailedAlert = function() {
		};
		ajax.encodeURIString = true;
		ajax.onCompletion = function() {

			if ((ajax.response === "" || (typeof ajax.xmlhttp.status != "undefined" && ajax.xmlhttp.status != 200))
					&& typeof errorCallback == "function") {
				errorCallback(ajax);
				return true;
			}

			callback(ajax.response);
		};

		for ( var option in options) {
			if (option === null) {
				continue;
			}
			ajax.setVar(option, options[option]);
		}

		try {
			ajax.runAJAX();
		} catch (e) {
			if (typeof errorCallback != "undefined") {
				errorCallback(ajax);
			}
		}
	};

	this.preg_replace_callback = function(pattern, callback, subject, limit) {
		// Perform a regular expression search and replace using a callback
		// 
		// discuss at: http://geekfg.net/
		// + original by: Francois-Guillaume Ribreau (http://fgribreau)
		// * example 1:
		// preg_replace_callback("/(\\@[^\\s,\\.]*)/ig",function(matches){return
		// matches[0].toLowerCase();},'#FollowFriday @FGRibreau @GeekFG',1);
		// * returns 1: "#FollowFriday @fgribreau @GeekFG"
		// * example 2:
		// preg_replace_callback("/(\\@[^\\s,\\.]*)/ig",function(matches){return
		// matches[0].toLowerCase();},'#FollowFriday @FGRibreau @GeekFG');
		// * returns 2: "#FollowFriday @fgribreau @geekfg"

		limit = !limit ? -1 : limit;

		var _check = pattern.substr(0, 1), _flag = pattern.substr(pattern
				.lastIndexOf(_check) + 1), _pattern = pattern.substr(1, pattern
				.lastIndexOf(_check) - 1), reg = new RegExp(_pattern, _flag), rs = null, res = [], x = 0, list = [], depth = "", ret = subject;

		String.prototype.repeat = function(num) {
			return new Array(num + 1).join(this);
		};

		// This may generate urls like "../test/../test"
		depth = this.page.substr(0, this.page.lastIndexOf("/") + 1);

		if (limit === -1) {
			var tmp = [];

			do {
				tmp = reg.exec(subject);
				if (tmp !== null) {
					res.push(tmp);
				}
			} while (tmp !== null && _flag.indexOf('g') !== -1);
		} else {
			res.push(reg.exec(subject));
		}

		for (x = res.length - 1; x > -1; x--) {// explore match
			if (!list[res[x][0]]) {
				ret = ret.replace(new RegExp(res[x][0], "g"), callback(res[x],
						depth));
				list[res[x][0]] = true;
			}
		}
		return ret;
	};

	this.init = function(event) {
		if (!event) {
			var event = window.event;
		}
		if (event) {
			event.cancelBubble = true;
			event.returnValue = false;
			if (event.stopPropagation) {
				event.stopPropagation();
			}
			if (event.preventDefault) {
				event.preventDefault();
			}
		}
		this.event = event;
	};

	this.removeOldViewer();
	this.displayContent(showContent, isImage, width, height);
};

var checkImageRoutine = function(inputImage) {

	this.image = null;
	this.counter = 500;
	this.isFinished = false;

	this.checkImages = function() {

		var isOK = this.isImageOk();
		if (!isOK && this.counter > 0) {
			this.counter--;
			return false;
		}

		if (isOK) {
			this.isFinished = true;
		}
		return true;
	};

	this.isImageOk = function(img) {

		if (this.isFinished) {
			return true;
		}

		if (!img) {
			img = this.image;
		}
		// During the onload event, IE correctly identifies any images
		// that weren't downloaded as not complete. Others should too.
		// Gecko-based browsers act like NS4 in that they imageflow this
		// incorrectly: they always return true.
		if (!img.complete) {
			return false;
		}

		// However, they do have two very useful properties: naturalWidth
		// and naturalHeight. These give the true size of the image. If
		// it failed to load, either of these should be zero.
		if (typeof img.naturalWidth != "undefined" && img.naturalWidth === 0) {
			return false;
		}

		// No other way of checking: assume it's ok.
		return true;
	};

	this.checkLoadImage = function(count, callback) {

		if (!count || count === 0) {
			if (callback && callback.error) {
				callback.error();
			}
			return false;
		}
		if (!this.isImageOk()) {
			var self = this;
			setTimeout(function() {
				self.checkLoadImage(count - 1, callback);
			}, 100);
			return;
		}

		if (callback && callback.finalize) {
			callback.finalize();
		}
		return true;
	};

	this.finish = function() {
		this.counter = 0;
	};

	this.image = inputImage;
	this.image.onload = this.finish;
	this.image.onabord = this.finish;
};

var iframeProxy = function(ajax, srcForm) {

	// Setup
	this.iframe = null;
	this.ajax = ajax;
	this.name = "iframeProxy"
			+ escape(this.ajax.requestFile
					.replace(new RegExp("[\\W]", "g"), "")) + "_"
			+ Math.round(Math.random() * 1000000);
	this.error = false;
	this.srcForm = srcForm;

	this.onCompletion = function(self) {

		try {
			self.ajax.responseXML = window.frames[self.iframe.id].document;
		} catch (e) {
			try {
				self.ajax.response = window.frames[self.iframe.id].document.body.innerHTML;
			} catch (ee) { /* DEAD END */
			}
		}

		self.ajax.execute = self;

		try {
			self.ajax.onCompletion();
		} catch (ee) {
			self.error = ee;
			alert(ee);
			return false;
		}

		// Clean Up
		var self2 = self;
		window.setTimeout(function() {
			if (self2.iframe && self2.iframe.parentNode) {
				self2.iframe.parentNode.removeChild(self2.iframe);
			}
		}, 500);

		return true;
	};

	// Return on duplicate
	if ($(this.name)) {
		this.error = "iframe exists";
		return;
	}

	// Build Frame
	this.iframe = document.createElement("iframe");

	this.iframe.src = this.ajax.requestFile !== null ? this.ajax.requestFile
			: this.srcForm.getAttribute('action');
	this.iframe.name = this.name;
	this.iframe.id = this.name;
	this.iframe.width = "0px";
	this.iframe.height = "0px";
	this.iframe.style.display = "none";
	this.iframe.frameBorder = false;

	var self = this;
	var wrapEvent = function() {
		self.onCompletion(self);
	};

	addEvent(this.iframe, 'load', wrapEvent);

	try {
		document.getElementsByTagName("body")[0].appendChild(this.iframe);
		this.srcForm.target = this.name;
		this.srcForm.onsubmit = function() {
		};

		addEvent(this.iframe, 'load', wrapEvent);
		// Stupid Event Creation in Iframes
		if (this.iframe.addEventListener) {
			this.iframe.addEventListener('load', wrapEvent, false);
		} else if (this.iframe.attachEvent) {
			this.iframe.attachEvent('onload', wrapEvent);
		} else {
			this.srcForm.submit();
		}

	} catch (e) { /* DEAD END */
		this.error = e;
		alert("Dead End: " + e);
	}
};

/* XXXXXXXXXX end of lib/plugins/popupviewer/script.js XXXXXXXXXX */



/* XXXXXXXXXX begin of lib/plugins/info/script.js XXXXXXXXXX */



/* XXXXXXXXXX end of lib/plugins/info/script.js XXXXXXXXXX */



/* XXXXXXXXXX begin of lib/plugins/keywords/script.js XXXXXXXXXX */



/* XXXXXXXXXX end of lib/plugins/keywords/script.js XXXXXXXXXX */



/* XXXXXXXXXX begin of conf/userscript.js XXXXXXXXXX */



/* XXXXXXXXXX end of conf/userscript.js XXXXXXXXXX */

addInitEvent(function(){ ajax_qsearch.init('qsearch__in','qsearch__out'); });
addInitEvent(function(){ addEvent(document,'click',closePopups); });
addInitEvent(function(){ addTocToggle(); });
addInitEvent(function(){ initSizeCtl('size__ctl','wiki__text'); });
addInitEvent(function(){ initToolbar('tool__bar','wiki__text',toolbar); });
addInitEvent(function(){ initChangeCheck('Nog niet bewaarde wijzigingen zullen verloren gaan.\nWeet je zeker dat je wilt doorgaan?'); });
addInitEvent(function(){ locktimer.init(840,'Je exclusieve gebruiksrecht voor het aanpassen van deze pagina verloopt over een minuut.\nKlik op de Voorbeeld-knop om het exclusieve gebruiksrecht te verlengen.',1); });
addInitEvent(function(){ scrollToMarker(); });
addInitEvent(function(){ focusMarker(); });

