var marge = 12, // before scrolling kicks in
 rand = '2px solid', // stijl van plaats
 randover = '#3333ff', // kleur bij wijzen
 randop = '#ff3333', // kleur bij klik
 men, man, map, mat, max, // objects
 d = window.document, aim = { x:0, y:0 }, aw=0, ah=0, p = 'px', // constants
 tig = null, tim = null; // timers

function help() {
 var v = getwindow(),
  s = d.getElementById( 'help' ).firstChild.nodeValue;
 s = s.replace( /winwidth/, v.w ).replace( /winheight/, v.h );
 leg();
 if( window.confirm( s ) ) { window.location.href = aw===1200 ? '?m=detail' :'?m=overzicht' ; }
 window.scrollTo( v.l, v.t );
 return false;
}

function lan( s ) { return s.replace( /B\b\.?/, 'Baai' ).replace( /\BB/, 'b' ).replace( /E\b\.?/, 'Eiland' ).replace( /^P\b\.?/, 'Poeloe' ).replace( /Pt?\.?$/, 'Punt' ).replace( /Res\./, 'Residentie' ).replace( /St\./, 'Sint' ).replace( /Str\./, 'Straat' ); }

function leg() { window.scrollTo( 9e9, 9e9 ); return false; }

function tog() {
 var h = this.scrollHeight + p, e = this.parentNode, o = e.parentNode.firstChild;
 if( !e.nextSibling.nextSibling ) {
  map.style.display = map.style.display ? '' : 'none';
 } else {
  if( !e.style.height ) { e = null; }
  do { o.style.height = o===e ? '' : h; } while( ( o = o.nextSibling ) && o.nextSibling.nextSibling );
 }
 return false;
}

function zet( e ) {
 e = e || window.event || {};
 var v = getwindow();
 men.style.left = v.l + v.w - men.scrollWidth - 1 + p;
 men.style.top = v.t + p;
 map.firstChild.alt = 'Beeld: ' + v.w + ' x ' + v.h + ' px';
 mat.style.left = Math.round( v.l*118/aw ) + p;
 mat.style.top = Math.round( v.t*80/ah ) + map.offsetTop + p;
 mat.style.width = Math.round( v.w*118/aw ) + p;
 mat.style.height = Math.round( v.h*80/ah ) + p;
 window.status = v.h - men.offsetHeight;
}

function md( e, o ) {
 e = e || window.event || {}; var a = !o;
 o = o || this; o = o.im || o; o.style.border = rand + ' ' + randop;
 var v = getwindow(), dx=0, dy=0, mx=0, my=0,
  l = parseInt( o.style.left, 10 ), t = parseInt( o.style.top, 10 ),
  w = o.width, h = o.height;
 if( t - v.t < men.scrollHeight ) {
  v.w -= men.scrollWidth;
 }
 if( a ) {
 if( v.l>l ) { aim.x = l - marge;  }
 if( v.l+v.w<l+w ) { aim.x = l + w + - v.w + marge; }
 if( v.t>t ) { aim.y = t - marge; }
 if( v.t+v.h<t+h ) { aim.y = t + h + - v.h + marge; }
 go();
  dx = v.l - aim.x;
  dy = v.t - aim.y;
  if( typeof e.pageX==='number' ) {
   mx = e.pageX - 4;
   my = e.pageY - 3;
  } else {
   mx = e.x + v.l - 4;
   my = e.y + v.t - 5;
  }
  var borderwidth = '3px 0 0 3px';
  if( my>t ) { borderwidth = '0 0 3px 0';
   if( my>t+h ) { t += h; borderwidth = '0 0 3px 3px'; }
  }
 // if( mx<l+w+dx ) { alert( 'Naar rechts!' ); }
  man.style.borderWidth = borderwidth;
  man.style.left = Math.min( mx, l ) + w + p;
  man.style.top = Math.min( my, t ) + p;
  man.style.width = Math.abs( mx - l - dx - w ) + p;
  man.style.height = Math.abs( my - t - dy ) + p;
  if( tim ) { window.clearTimeout( tim ); }
  tim = window.setTimeout( 'ren();', 1500 );
 }
}

function mp() { mv( this.im );
 max.style.left = Math.round( ( this.im.offsetLeft + this.im.width / 2 ) / aw * 118 - 2 ) + p;
 max.style.top = Math.round( ( this.im.offsetTop + this.im.height / 2 ) / ah * 80 - 2 + map.offsetTop ) + p;
}

function mo( o ) {
 o = o || this; o = o.im || o; o.style.border = ''; max.style.left = '';
}

function mv( o ) {
 o = o || this; o.style.border = rand + ' ' + randover; ren();
}

function mu() { mo( this ); }

function mc( e ) {
 md( e, this );
 var s = lan( this.alt );
 if( window.confirm( s.replace( /Gg/, 'Goenoeng' ) + '\n\nOpzoeken?' )) {
  window.location.href = 'vind.php?q=' + s.replace( /Gg\s+/, '' ).replace( /Eiland K/, 'K' );
 }
}

function go() {
 var u, v = getwindow(), dx = Math.floor( ( v.l - aim.x )/2 ), dy = Math.floor( ( v.t - aim.y )/2 );
 if( dx ) { v.v.scrollLeft = v.l - dx;  }
 if( dy ) { v.v.scrollTop = v.t - dy;  }
 if( tig ) { window.clearTimeout( tig ); }
 u = getwindow();
 if( v.l!==u.l || v.t!==u.t ) {
  tig = window.setTimeout( 'go();', 40 );
 }
}

function rem() {
 map.onmousemove = null;
 map.onmouseup = null;
 map.onmouseout = ret;
}
function ret() { mat.style.borderColor = ''; }
function ren() { man.style.left = ''; if( tim ) { window.clearTimeout( tim ); } }
function rf() { return false; }

function getmouse( e, v ) {
 e = e || window.event || {}; v = v || getwindow();var x,y;
 if( typeof e.pageX==='number' ) {
  x = e.pageX;
  y = e.pageY;
 } else {
  x = e.x + v.l;
  y = e.y + v.t;
 }
 return { x: x, y: y };
}

function getwindow() {
 var v = window, w, h, l, t;
 if( typeof v.innerWidth==='number' ) {
  w = v.innerWidth;
  h = v.innerHeight;
  l = v.pageXOffset;
  t = v.pageYOffset;
 } else if( ( v = d.documentElement ) &&
   typeof v.clientWidth==='number' &&
   v.clientWidth !== 0 || ( v = d.body ) ) {
  w = v.clientWidth;
  h = v.clientHeight;
  l = v.scrollLeft;
  t = v.scrollTop;
 }
 return { w: w, h: h, l: l, t: t, v: v };
}

( function() {
if( d.getElementById && d.createElement ) {
 aw = d.images[0].width;
 ah = d.images[0].height;
 men = d.getElementById( 'menu' );
 man = d.getElementById( 'man' );
 map = d.getElementById( 'map' );
 mat = d.getElementById( 'mat' );
 max = d.getElementById( 'max' );
 var l = d.getElementById( 'loca' ),
  m = window.location.search && unescape( window.location.search.substring(1).replace( /\+/g, ' ' ) ) || '',
  mm = aw===1200 ? function(n){return n;} : function(n){return Math.round( n* aw/1200 );},
  r = ( men.firstChild.nodeValue+' 0 0 0 0' ).match( /([\D]+\s+\d+\s+\d+\s+\d+\s+\d+)\s*/g ),
  a = d.createElement( 'a' ), b, c,
  e = d.createElement( 'div' ), f, 
  g = d.createElement( 'img' ), h, i = 0, j, k, n = r.length;
 a.insertBefore( d.createTextNode( '#' ), null );
 g.src = '/blank.gif';
 m = m.indexOf( 'l=' )>-1 ? m.replace( /^.*l=([^&]+).*$/, '$1' ).toLowerCase() : 'e. krakatau';
 men.removeChild( men.firstChild );
 map.onmouseover = function() { mat.style.borderColor = '#903030'; };
 map.onmouseout = ret;
 map.ondragstart = rf;
 map.onselectstart = rf;
 map.onmousedown = function( e ) {
  function m() {
   var c = getmouse( e );
   c.x -= map.parentNode.offsetLeft;
   c.y -= map.offsetTop + map.parentNode.offsetTop;
   aim.x = Math.round( aw/118 * Math.max( 0, Math.min( 120 -mat.offsetWidth, c.x - Math.round( mat.offsetWidth/2 ) ) ) );
   aim.y = Math.round( ah/80 * Math.max( 0, Math.min( 82 - mat.offsetHeight, c.y - Math.round( mat.offsetHeight/2 ) ) ) );
   go();
  }
  m();
  map.onmousemove = m;
  map.onmouseout = rem;
  map.onmouseup = rem;
 };
 for( ; i<n; i++ ) {
  j = r[i].match( /^\s*(.+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s*$/ );
  if( ( k=j[1].match( /^=([^=]+?)\s*=\s*(.+)$/ ) ) ) {
   c = a.cloneNode( true );
   c.href = '#'+ k[1];
   c.className = 'h';
   c.onclick = tog;
   c.firstChild.nodeValue = k[1];
   f = e.cloneNode( true );
   f.insertBefore( c, null );
   men.insertBefore( f, map );
   if( !e.style.height ) { e.style.height = c.scrollHeight + p; f.style.height = c.scrollHeight + p; } 
   j[1] = k[2];
  }
  b = a.cloneNode( true );
  b.href = '?l='+ j[1];
  b.onclick = rf;
  b.onmousedown = md;
  b.onmouseover = mp;
  b.onmouseout = mo;
  b.firstChild.nodeValue = lan( j[1] );//Sebulu
  h = g.cloneNode( true );
  h.alt = j[1];
  h.width = mm(j[2]);
  h.height = mm(j[3]);
  h.style.left = mm(j[4]) + p;
  h.style.top = mm(j[5]) + p;
  h.onmousedown = mc;
  h.onmouseout = mu;
  if( aw===1200 ) { h.onmouseover = mv; }
  b.im = h;
  l.insertBefore( h, null );
  f.insertBefore( b, null );
 }
 if( d.getElementById( 'k' ) ) {
  d.getElementById( 'k' ).onclick = function() {
   d.getElementById( 'copy' ).style.display = this.checked ? '' : 'none';
  };
 }
 if( m ) { m = 'l=' + m.replace( / /g, '' );
  for( ; f=f.previousSibling; ) {
   a = f.childNodes; i = a.length;
   while(i--) {
    if( a[i].href.toLowerCase().replace( / /g, '' ).indexOf( m ) >-1 ) {
     j = a[i].im; k = getwindow();
     window.scrollTo( j.offsetLeft + j.offsetWidth/2 - k.w/2, j.offsetTop + j.offsetHeight/2 - k.h/2 ); break;
    }
   }
  }
 }
 if( d.layers ) { d.captureEvents( Event.MOUSEMOVE ); }
 window.onresize = zet; window.onscroll = zet; d.onmousemove = zet;
 zet();
}
} )();
