var cur = null, d = window.document, foundlist = [], foundnhead = 'Gemarkeerd: ', hola = null,
 gid = d.getElementById ? function( o ) { return d.getElementById( o ) || null; } : ( d.all ? function( o ) { return d.all( o ) || null; } : null );

var navs = {
 'mart': [ 'Niets in de marge:/image/icon/calendar16yellow.gif', 'Context in de marge:/image/icon/calendar16red.gif' ],
 'font': [ 'Antiqua lettertype:/image/icon/s11.gif', 'Palatino lettertype:/image/icon/s11lite.gif', 'Perpetua', 'Palatino Linotype', 'Book Antiqua', 'Georgia', 'Garamond', 'Times New Roman', 'Maiandra GD', 'Sylfaen', 'Monotype Corsiva' ]
},
 qran = 'huis, sandick, woord, hart, goud, west';

function ali( s ) { window.alert( s ); return false; }
function ari( s ) { return s.replace( /([\\\/|^$()[\]{}.*+?])/g, '\\$1' ); }

function ani() {
 var v = getwindow();
 if( cur ) {
  cur.style.top = Math.round( Math.max( 12, v.t + ( v.h - cur.height ) / 2 ) ) + 'px';
  cur.style.left = Math.round( Math.max( 12, v.l + ( v.w - cur.width ) / 2 ) ) + 'px';
 }
 if( gid( 'sf' ) && window.navigator.platform.indexOf( 'Mac' )<0 ) {
  gid( 'sf' ).style.top = Math.max( 0, v.t ) + 'px';
  v.t += gid( 'sf' ).scrollHeight;
 }
 if( gid( 'map' ) && gid( 'p1' ) ) {
  gid( 'map' ).style.top = Math.round( Math.max( gid( 'p1' ).offsetTop, v.t + 12 ) ) + 'px';
 }
}

function changecss( sel, prop, val ) {
 sel = sel.replace( /^(\w+)/, function( t, a ) { return a.toUpperCase(); } );
 var i, r, s = d.styleSheets && d.styleSheets[0]; if( s ) {
  r = s.rules ? s.rules : s.cssRules; if( r ) {
   i = r.length; while(i--) {
    if( r[i].selectorText===sel ) {
     r[i].style[prop] = val; return true;
    }
   }
   return ali( 'Style not found in ' + r.length + ' rules.' );
  }
  return ali( 'Stylesheet not found.' );
 }
}

function getcookie( name ) { name += '=';
 var s = d.cookie, i = s.indexOf( name ), start, end;
 if( i < 0 ) { return null; }
 start = i + name.length;
 end = s.substring( start ).indexOf( ';' );
 return unescape( s.substring( start, end < 0 ? s.length : (start + end) ) );
}

function gettext( o ) {
 for( var i = 0, n = o.childNodes.length, p, s = ''; i<n; i++ ) {
  p = o.childNodes[i];
  if( p.nodeType==3 ) {
   s +=  ' ' + ( p.nodeValue || '' );
  } else if( p.nodeType==1 || p.nodeType==9 ) {
   s +=  ' ' + gettext( p );
  }
 }
 return s.replace( /\s+/, ' ' );
}

function getwindow( o ) { o = o || window; var w, h, l, t, x, y; if( typeof o.innerWidth==='number' ) { w = o.innerWidth; h = o.innerHeight; l = o.pageXOffset; t = o.pageYOffset; x = o.scrollMaxX; y = o.scrollMaxY; } else if( ( o = d.documentElement ) && typeof o.clientWidth==='number' && o.clientWidth || ( o = d.body ) ) { w = o.clientWidth; h = o.clientHeight; l = o.scrollLeft; t = o.scrollTop; x = o.scrollWidth; y = o.scrollHeight; } return {w: w, h: h, l: l, t: t, x: x, y: y}; }

function gocur(e,o,s,w,h) { e = e || window.event; o = o || e.srcElement || e.target;
 if( o.ur && !cur ) {
  cur = o.ur;
 } else {
  var i = d.createElement( 'img' );
  i.src = s||'/blank.gif'; i.alt = '';
  i.width = w||100;
  i.height = h||100;
  i.style.position = 'absolute';
  i.style.background = 'threedface';
  i.style.border = '2px outset white';
  i.style.padding = '2px';
  d.body.insertBefore( i, null );
  i.onmouseout = uncur;
  o.onmouseout = uncur;
  o.ur = i;
  cur = i;
 }
 ani();
}

function uncur( e ) { e = e || window.event; if( e.toElement===cur || e.relatedTarget===cur ) { return; } if( cur ) { cur.style.left = '-9999px'; cur = null; } }

function listwords( s ) {
 s = s || d.selection.createRange().text  || gettext( d.body );
 var a = s.match(/\b[\w\u00A0-\u00FF]+?\b/g).sort(), b={}, c = [], i = a.length, n, t;
 if( a ) {
  while(i--) { b[a[i]] = b[a[i]] ? b[a[i]] + 1:1; }
  for(i in b) { c.push([b[i],' '+i]); }
  c.sort( function(a,b) { var x = b[0] - a[0]; return x || ( b[1].toLowerCase()<a[1].toLowerCase()?1:-1 ); } );
  c = c.glue().replace( /(\d+),/g, '$1 x\t' ).split( /\n/ );
  i = 40; n = c.length; t = n + ' woord' + ( n===1 ? '' : 'en' ) + ':\n\n';
  if( i+5>n ) {
   return ali( t + c.glue() );
  } else {
   t = ' van ' + t;
   while( window.confirm( 'Top ' + ( i - 39 ) + ' tot ' + Math.min( n, i ) + t + c.slice( i - 40 , i ).glue() + '\n\nVerder?' ) ) {
    if( i>n ) { i = 0; } i += 40;
   }
  }
 } else { return ali( 'Geen woorden gevonden.' ); }
}

function listphrases( q, s ) {
 q = ari( q || gid( 'q' ).value );
 s = s || d.selection && d.selection.createRange().text || gettext( d.body );
 var re = new RegExp( '.{15}' + q + '.{15}', 'gi' ), ma = s.match( re );
 return ali( ma ? ma.length + ' keer "' + q + '":\n\n' + ma.glue() : 'Geen "' + q + '" gevonden.' );
}

function tognav( o ) { o = o || this;
 var h = o.href.substring( 1 ), i, j, k, flag;
 if( navs[h] ) {
  j = navs[h][0].split( /\s*:\s*/ ); k = navs[h][1].split( /\s*:\s*/ );
  flag = o.style.backgroundImage.indexOf( j[1] )<0;
  if( h==='font' ) { changecss( 'body', 'font', flag ? "100% 'Palatino Linotype', serif" : "100% 'Book Antiqua', 'Maiandra GD', serif" ); }
  if( h==='mart' ) { changecss( '.g', 'display', flag ? 'block' : 'none' ); }
  o.style.backgroundImage = 'url( ' + ( flag ? j[1] : k[1] ) + ' )';
  o.firstChild.firstChild.nodeValue = flag ? j[0] : k[0];
 }
 return false;
}

function buildnav() {
 if( gid( 'nav' ) ) {
  var g = gid( 'nav' ), h, i, j, k, l = g.firstChild;
  for( i in navs ) {
   j = navs[i][0].split( /\s*:\s*/ );
   h = l.cloneNode( true );
   h.href = '#' + i;
   h.onclick = tognav;
   h.style.backgroundImage = 'url( ' + j[1] + ' )';
   h.firstChild.firstChild.nodeValue = j[0];
   g.insertBefore( h, null );
  }
 }
}

function buildq() {
 var h, i, j, k, l, m, n, a;
 h = d.createElement( 'form' ); h.action='/zoek'; h.id = 'sf';
 h.style.position = 'absolute';
 h.style.right = '12px';
 i = d.createElement( 'div' );
 l = i.cloneNode( true ); l.style.background='url(/image/icon/hammer.gif) bottom right no-repeat';
 l.onmousedown = function( e ) { e = e || window.event; if( ( e.srcElement || e.target )===this ) { listwords(); } };
 j = d.createElement( 'input' );
 k = j.cloneNode( true );
 a = d.createElement( 'a' ); a.href = '#q'; a.style.display = 'none'; a.insertBefore( d.createTextNode( 'x ' ), null );
 j.type = 'text'; j.id = 'q'; j.name = j.id; j.size = 12;
 j.value = unescape( ( '&' + ( window.location.search || ' ' ).substring( 1 ) + '&' + ( d.referrer || '' ) + '&q=' + ( getcookie( 'q' ) || ran( qran ) ) ).replace( /^.*?[&?]q=([^&?]*).*$/, '$1' ) ).replace( /\+/g, ' ' );
 j.onfocus = function() { this.select(); };
 j.onkeyup = j.onmouseup = toa; j.onpaste = topaste;
 j.accessKey= 's'; j.title = ' Sla uw slag. Ook in Unicode. Alt+S ';
 k.type = 'submit'; k.value = ' ';
 m = k.cloneNode( true );
 n = k.cloneNode( true );
 k.style.backgroundImage = 'url( /image/icon/find13.gif )';
 k.accessKey= 'z'; k.title = ' Zoek op de website. Alt+Z ';
 m.onclick = function() { window.location.href = 'http:\/\/www.google.com/search?q=' + this.form.elements.q.value; return false; };
 m.style.backgroundImage = 'url( /image/icon/google13.gif )';
 m.accessKey= 'g'; m.title = ' Zoek op het internet met Google. Alt+G ';
 n.style.backgroundImage = 'url( /image/icon/hi14off.gif )';
 n.onclick = function( e ) { e = e || window.event;
  var b = e.shiftKey, r = trim( this.form.elements.q.value ), s = r.split( /\s+/ ), t = 0, u = 0, v = s.length;
  if( !v ) { unlite(); return false; }
  for( ; u<v; u++ ) { if( foundlist.indexOf( s[u] )<0 ) { t += highlight( s[u], b ); } }
  if( !t ) { if( foundlist.indexOf( r )<0 ) { unlite(); } else { unlite( r ); } }
  return false;
 };
 n.accessKey= 'm'; n.title = ' Markeer. Alt+M +Shift: alleen hele woorden';
 i.insertBefore( j, null );
 i.insertBefore( n, null );
 i.insertBefore( k, null );
// i.insertBefore( m, null );
 l.insertBefore( a, null );
 h.insertBefore( i, null );
 h.insertBefore( l, null );
 d.body.insertBefore( h, null ); toa();
 if( gid( 'nav' ) ) { gid( 'nav' ).style.top = h.offsetHeight + 'px'; }
 d.onkeydown = keyd;
 d.onmouseup = selt;
}

function topaste() { var r, s = this.value;
 if( d.selection && (r = d.selection.createRange()) && !r.text || ( r.text!==s ) ) { window.event.returnValue = true; toa(); return true; }
 window.event.returnValue = false;
 this.value = window.clipboardData.getData( 'Text', 'was:' + s );
 toa();
}

function toa() {
 var b, q = gid( 'q' ), p = q.parentNode.nextSibling, c = p.childNodes, f = c[0], i = c.length, j, k,
  r = /(\\u\d+)/g, s = f.firstChild.nodeValue + ' ' + q.value;
 if( r.test( s ) ) { s = s.replace( r, function(t,a) { return eval('"'+a+'"'); } ); }
 if( s!==gettext( p ) ) {
  s = s.split( /\s+/ ).unique();
  while( i ) {
   if( ( j = c[i--] ) && s.indexOf( gettext( j ) )<0 ) { p.removeChild( j ); }
  }
  i = s.length;
  if( c.length<i+1 ) {
   while( c.length<i ) {
    b = f.cloneNode( true );
    b.onclick = b.onkeyup = tos;
    j = c.length%10;
    b.accessKey = j; b.title = ' Alt+' + j + ' +Ctrl: achterwaarts. ';
    b.style.cursor = 'help';
    b.style.display = '';
    p.insertBefore( b, null );
   }
   while(i--) {
    j = c[i].firstChild; k = s[i];
    if( j.nodeValue!==k ) {
     j.nodeValue = k;
     c[i].href = '?q=' + escape( k );
     if( foundlist.indexOf( k )>-1 ) { c[i].className = 'qh' + foundlist.indexOf( k ); }
}}}}}

function tos( e, s ) { e = e || window.event; s = trim( s || gettext( this ) );
 if( !s ) { return false; }
 var b = 0, e, n = 0, r,
  alas = function() { return ali( '"' + s + '" is ' + ran( [ 'niet te vinden', 'onvindbaar' ] ) + '.' ); },
  good = function() { var o = r.parentElement();
   do { if( o.id==='nav' || o.id==='sf' || o.id==='toq' || ( /\bhid\b/.test( o.className || '' ) ) || ( o.style && o.style.display==='none' ) ) { return false; } }
    while( ( o = o.parentNode ) ); return true;
  },
  grab = function() { return r.findText( s, b?-1:1, b ); },
  look = function() { return grab() || ( n += r.moveStart( 'textedit', b?1:-1 ) ) && grab(); },
  step = function() { return b ? r.moveEnd( 'character', -1 ) : r.moveStart( 'character', 1 ); };
 if( d.selection ) {
  r = d.selection.createRange();
  if( !e.keyCode || e.keyCode>40 ) {
   if( e.ctrlKey ) { b += 1; }
   if( r.text && good() ) {
    step();
   } else {
    d.selection.empty();
    r = d.selection.createRange();
    r.moveToElementText( d.body.firstChild );
   }
   if( look() ) {
    if( !good() ) {
     while( step() && look() && Math.abs( n )<3 ) {
      if( good() ) { break; }
     }
    }
    if( good() ) {
     r.select(); r.scrollIntoView();
     if( r.offsetTop<36 ) { scrollup( 36 - r.offsetTop ); }
     else if( getwindow().h-r.offsetTop-r.boundingHeight<36 ) { scrollup( 36 - getwindow().h + r.offsetTop + r.boundingHeight, 1 );
     }
    } else { return alas(); }
   } else { return alas(); }
  }
  try{ r.parentElement().focus(); } catch(e) { return ali( '"' + s + '" is niet geselecteerd:\n\n' + e.message ); }
 } else if( window.find ) {
  if( !window.find( s ) ) { while( window.find( s, false, true ) ) { ++n; } } else { ++n; }
  if( !n ) { return alas(); }
 }
 return false;
}

function highlight( t, wholeword, el ) {
  wholeword = wholeword || false;
  t = ari( t );
  if( !trim( t ) ) { return 0; }
  var r, p = gid( 'case' ) && gid( 'case' ).checked ? 'g' : 'gi';
  if( gid( 'phrase' ) && gid( 'phrase' ).checked ) {
    r = new RegExp( wholeword ? '\\b' + t + '\\b' : t, p );
  } else {
    r = new RegExp( ( wholeword ? '\\b(' + t + ')\\b' : t ).split( /\s+/ ).join( '|' ), p );
  }
  var s = [el||d.documentElement||d.body.firstChild], i = 0, n=0, e, j, l, o, k;
  var h = d.createElement('span');
  h.className = 'qh' + foundlist.length%10;
  do {
    e = s[i];
    if( e.nodeType===3 ) {
      r.lastIndex = 0;
      l = r.exec( e.nodeValue );
      if( l!==null ) {
        k = l[0].length;
        if( r.lastIndex>k ) {
          e.splitText( r.lastIndex-k );
          e = e.nextSibling;
        }
        if( e.nodeValue.length>k ) {
          e.splitText( k );
          s[i++] = e.nextSibling;
        }
        o = h.cloneNode( true );
        o.insertBefore( d.createTextNode( l[0] ), null );
        e.parentNode.replaceChild( o, e ); n++;
      }
    } else {
      j = e.childNodes.length;
      while( j ) { s[i++] = e.childNodes.item( --j ); }
    }
  } while(i--);
  if( n>1 ) {
   window.defaultStatus = foundnhead + ' ' + ( n - 1 ) + 'x ' + t + ( wholeword ? ' (ww)' : '' ) + window.defaultStatus.substring( foundnhead.length );
   foundlist[ foundlist.length ] = t;
  }
  return n;
}

function unlite( s ) {
 var a = [], c = 'qh', i, j, l = foundlist.length, k = s ? foundlist.indexOf( s ) : -1, t;
 if( l ) {
  if( k>-1 ) {
   for( i = 0; i<l; i++ ) { if( i!==k ) { a.push( this[i] ); } }
   foundlist = a; window.defaultStatus = window.defaultStatus.replace( new RegExp( '\\s+\\d+x ' + s + '\\b' ), '' );
   c += k;
  } else {
   foundlist = []; window.defaultStatus = '';
  }
  a = d.body.getElementsByTagName( 'span' ); i = a.length;
  while(i--) { j = a[i];
   if( j.className.indexOf( c )===0 ) {
    t = d.createTextNode( j.firstChild.nodeValue );
    j.parentNode.replaceChild( t, j );
   }
  }
 }
 return false;
}

function hop( o ) { o = o || this;
 if( o && !hola && window.navigator.platform.indexOf( 'Mac' )<0 ) {
  var i, x, y = Math.random() * 40 + 40; hola = o.lastChild;
  for(i=0;i<y;i+=0.2) {
   x = Math.abs( Math.round(Math.sin(i/(4-2*(i/y)))*(1-(i/y)*(i/y))*40) );
   window.setTimeout('if( hola ) { hola.style.paddingRight = \'' + Math.round( x ) + 'px\'; }', y * i * 1.5 );
  }
  window.setTimeout( 'hola = null;', y * y * 1.5 );
 }
}

function selt( e ) { e = e || window.event;return;
 var i = gid( 'bb' ), r = d.selection && d.selection.createRange && d.selection.createRange(), s = isselect(), t = r && r.parentElement(), u, v;
 while( t && t.parentNode ) { if( t.tagName.toLowerCase()==='form' ) { t = false; } else { t = t.parentNode; } }
 if( r && s && t ) {
  u = r.getBoundingClientRect(); v = getwindow();
  if( !i ) {
   i = d.createElement( 'input' ); i.type = 'submit'; i.value = ' '; i.id = 'bb';
   i.style.position = 'absolute';
   i.style.backgroundImage = 'url( /image/icon/hi14off.gif )';
   d.body.insertBefore( i, null );
  }
  i.style.top = u.top + v.t  - 6 + 'px';
  i.style.left = u.right + v.l - 6 + 'px';
  i.onclick = function() {
   s = s.split( /\s+/ ); t = 0; u = 0; v = s.length;
   if( !v ) { unlite(); this.style.left = '-9999px'; return false; }
   for( ; u<v; u++ ) { if( foundlist.indexOf( s[u] )<0 ) { t += highlight( s[u], e.shiftKey ); } }
   if( !t ) { if( foundlist.indexOf( r )<0 ) { unlite(); } else { unlite( r ); } this.style.left = '-9999px'; }  
   return false;
  };
 } else if( i ) {
  i.style.left = '-9999px';
 }
}

function isselect() { if( d.selection && d.selection.createRange ) { return d.selection.createRange().text; } if( d.getSelection ) { return d.getSelection(); } return ''; }
function keyd( e ) { e = e || window.event; if( e.keyCode===85 ) { unlite(); } }
function play( o, t ) { if( gid( 'snd' ) ) { gid( 'snd' ).src = o.href; gid( 'snd' ).loop = t ? t : 'infinite'; return false; } return true; }
function ran( a ) { return a && a.length ? a[ Math.floor( Math.random() * a.length ) ] : ( !isNaN( a ) ? Math.ceil( Math.random() * a ) : Math.random() ); }
function scrollup( n, d ) { n=n||30; d=d||-1;for( var i=1; i<n; i++ ) { window.setTimeout( 'window.scrollBy(0,'+d+')', i*4+7 ); } }
function setcookie( name, val, end, p ) { d.cookie = name + '=' + escape( val ) + ( end ? '; expires=' + end.toGMTString() : '' ) + '; path=' + ( p || '/' ); }
function trim( s ) { return ( s || '' ).replace( /^\s*|\s*$/g, '' ); }

Array.prototype.indexOf = function( o ) { for( var i = 0, l = this.length; i<l; i++ ) { if( this[i]===o ) { return i; } } return -1; };
Array.prototype.glue = function () { return this.join( '\n' ); };
Array.prototype.unique = function( b ) { for(  var a = [], i=0, l = this.length; i<l; i++ ) { if( a.indexOf( this[i], 0, b ) < 0 ) { a.push( this[i] ); } } return a; };
Array.prototype.remove = function( n ) { for( var a = [], i=0, l = this.length; i<l; i++ ) { if( i!==n ) { a.push( this[i] ); } } return a; };

function ini(){
 var a, i, j;
 if( (j=gid( 'toq' )) && (j=j.firstChild) ) {
  qran =  [qran, j.nodeValue].join( ',' );
 }
 qran = qran.split( /\s*,+\s*/ );
 if( (j=gid( 'toe' )) && (j=j.firstChild) && j.firstChild ) {
  j.onmouseover = hop;
 }
 if( (j=gid( 'krant' )) ) {
  j.scrollLeft = 85;
 }
 if( (j=gid( 'toc' )) ) {
  a = j.childNodes; i = a.length;
  while( i-- ) { if( a[i].firstChild.hash ) { a[i].onclick = scrollup; } }
 }
 buildnav(); buildq(); ani();
 if( typeof window.onscroll==='undefined' ) {
  window.setInterval( 'ani();', 200 );
 } else {
  window.onresize = ani;
  window.onscroll = ani;
 }
}

window.onload = function() { window.setTimeout( 'ini();', 10 ); };

