// browser sniffer
function Browser(){
  this.uA = navigator.userAgent.toLowerCase();
  this.aN = navigator.appName.toLowerCase();
  this.iE = this.aN.indexOf('microsoft') != -1 ? 1 : 0;
  this.mac =  this.uA.indexOf('mac') != -1 ? 1 : 0;
  this.win = this.uA.indexOf('windows') != -1 ? 1 : 0;
  this.safari =  this.uA.indexOf('webkit') != -1 ? 1 : 0;
  this.opera =  this.uA.indexOf('opera') != -1 ? 1 : 0;
  this.operaMini =  this.uA.indexOf('mini') != -1 ? 1 : 0;
  this.mozilla = this.aN.indexOf('netscape') != -1 && !this.safari ? 1 : 0;
  this.winMozilla = this.mozilla && this.win ? 1 : 0;
  this.winIE = this.iE && this.win && !this.opera ? 1 : 0;
  this.winIE6Down = this.winIE && parseInt(this.uA.split('msie ')[1].substring(0,1)) <= 6 ? 1: 0;
  this.macIE = this.iE && this.mac ? 1 : 0;
};
var browser = new Browser();

if (!browser.operaMini){

// Opent een popup voor het tonen van een uitvergrote afbeelding
function zoomImage(imgUrl){
	var popup = window.open('','afbeelding','scrollbars=yes,resizable=yes,width=640,height=480');
	var html = '';
	html += '<html>';
	html += '<head><title>Koninklijke Bibliotheek - Afbeelding</title>';
	html += '<style>body { margin: 10px; background: #3F392F;}';
	html += ' .text { font-size: 0.6em; font-family: tahoma,verdana,arial,geneva;';
	html += ' color: #F0EAD8; display: block; margin-bottom: 5px;}</style>';
	html += '<scr'+'ipt>';
	html += 'var spaceX = 50; var spaceY = 80; var screenX = screen.availWidth;';
	html += 'var screenY = screen.availHeight; var image = new Image();';
	html += 'image.src = "'+imgUrl+'"; image.onload = function(){ imgX = this.width; imgY = this.height;';
	html += 'var x = spaceX + imgX; var y = spaceY + imgY; if (screenX<x) x = screenX-100;';
	html += 'if (screenY<y) y = screenY-100; window.resizeTo(x,y); window.moveTo(40,40); }';
	html += '</scr'+'ipt>';
	html += '</head>';
	html += '<body><span class="text">Klik op de afbeelding om dit venster te sluiten</span>';
	html += '<a href="javascript:window.close();"><img border="0" src="'+imgUrl;
	html += '" alt="Klik op de afbeelding om dit venster te sluiten." /></a><br/>';
	html += '</body>';
	html += '</html>';
	popup.document.write(html);
	popup.document.close();
	popup.focus();
	return false;
}

// 640x480 default
function popup(url){
	window.open(url,'','resizable=yes,width=640,height=480,scrollbars=yes,status=no');
	return false;
}

// 450x350 metalib
function popup2(url){
	window.open(url,'','resizable=yes,width=450,height=350,status=no');
	return false;
}

// 775x520 kiosk
function popup3(url){
	window.open(url,'','resizable=yes,width=775,height=520,status=no');
	return false;
}

// 1000x700 kiosk
function popup4(url){
	window.open(url,'','resizable=yes,width=1000,height=700,status=no');
	return false;
}

// 775x550 metalib
function popup5(url){
	window.open(url,'metalib','resizable=yes,width=775,height=550,location=yes,menubar=yes,scrollbars=yes,toolbar=yes,status=yes');
	return false;
}

// 750x550 koopman
function popup6(url){
	window.open(url,'','resizable=yes,width=750,height=550,location=no,menubar=no,scrollbars=yes,toolbar=no,status=no');
	return false;
}

// 906x590 tijdlijn
function popup7(url){
	window.open(url,'','resizable=yes,width=906,height=590,location=no,menubar=no,scrollbars=yes,toolbar=no,status=no');
	return false;
}


function ContactMe(prefix,suffix){
	var m =  Array(109,97,105,108,116,111,58);
	var s = '';
	for (var i = 0; i < m.length; i++){
		s += String.fromCharCode(m[i]);
	}
	window.location.replace(s + prefix + String.fromCharCode(8*8) + suffix);
	return false;
}

// addStyle
function addStyle(selector,properties){
  if (document.styleSheets) {
    var s = document.getElementsByTagName('STYLE');
    if (s.length == 0){
      var sheet = document.createElement('style');
      sheet.setAttribute('type','text/css');
      document.getElementsByTagName('HEAD')[0].appendChild(sheet);}
    if (browser.winIE){
      var lastSheet = document.styleSheets[document.styleSheets.length - 1];
      lastSheet.addRule(selector, properties);}
    else {var lastSheet = s[0];
      lastSheet.appendChild(document.createTextNode(selector + ' { ' + properties + ' }'));}
  	}
};
addStyle('.drempel','display:none !important;');
addStyle('.nomob','display:block !important;');

//incl. .js
if (window.jsPath == null)
var jsPath = "/scripts/";
document.write('<scr'+'ipt type="text/javascript" src="' + jsPath + 'jquery.js"><\/scr'+'ipt>');

// getElementById
function getEl(id){
  return document.getElementById(id);
};


//layout case switcher
var lastLayout;
var checkWindowWidth = function(){
	var mob = ((document.documentElement.clientWidth > 0 && document.documentElement.clientWidth < 680) || document.body.clientWidth < 680);
	var pda = (!mob && ((document.documentElement.clientWidth > 0 && document.documentElement.clientWidth < 990) || document.body.clientWidth < 990));
	var ppc = (!pda && !mob);

	if (mob && lastLayout != "mob"){
	  $("body").removeClass("pda ppc");
	  $("body").addClass("mob");
	  lastLayout = "mob";
	}
	else if (pda && lastLayout != "pda"){
	  $("body").removeClass("mob ppc");
	  $("body").addClass("pda");
	  lastLayout = "pda";
	}
	else if (ppc && lastLayout != "ppc") {
	  $("body").removeClass("mob pda");
	  $("body").addClass("ppc");
	  lastLayout = "ppc";
	}
};



/**
 * ##CLASSNAMES
 */
// in Array
function inArray(str, arr) {
  for(var i = 0, arrlen = arr.length; i < arrlen; i++) {
    if(str == arr[i])
      return true;
  }
  return false;
}

// getClassNames
function getClassNames(n) {
  if(!n)
    return false;
  return n.className.split(' ');
}

// addClass
function addClass(n, classStr) {
  if(!n)
    return false;
  n.className += (n.className ? ' ' : '') + classStr;
  return true;
}

// removeClass
function removeClass(n, classStr) {
  if(!n)
    return false;

  var classNames = getClassNames(n);
  for(var i = classNames.length; i >= 0; i--) {
    if(classStr === classNames[i])
      delete(classNames[i]);
  }
  return n.className = classNames.join(' ');
}

// hasClass
function hasClass(n, classStr) {
  if(!n)
    return false;
  return inArray(classStr, getClassNames(n));
}

/**
 * ##SETUPINFOBOXES
 */
function setupInfoboxes() {
  var searchengine = document.getElementById('searchengine');
  if(!searchengine || browser.winIE6Down || browser.macIE)
    return false;
  
  var shadows = ['shadow-t', 'shadow-tr', 'shadow-r', 'shadow-br', 'shadow-b', 'shadow-bl', 'shadow-l', 'shadow-tl'];
  var infolinks = searchengine.getElementsByTagName('span');
  var i = infolinks.length; while(i--) {
    if(hasClass(infolinks[i], 'info-description-content')) {
      infolinks[i].style.position = 'relative';
      var j = shadows.length; while(j--) {
        var shadowDiv = document.createElement('span');
        addClass(shadowDiv, 'shadow');
        addClass(shadowDiv, shadows[j]);
        infolinks[i].appendChild(shadowDiv);
      }
    }
    
    if(hasClass(infolinks[i], 'info')) {
      infolinks[i].onmouseover = function() {
        removeClass(this, 'info-hidden');
      }
      infolinks[i].onmouseout = function() {
        addClass(this, 'info-hidden');
      }
    }
  }
}



//DOM loader
var init = function() {
	if (arguments.callee.done) return;
	arguments.callee.done = true;
	if (_timer) clearInterval(_timer);
	checkWindowWidth();
  setupInfoboxes();
	//$('head').append('<style type="text/css">.drempel{display:none !important;}.nomob{display:block !important;}</style>');
	try {document.execCommand('BackgroundImageCache', false, true);} catch(e) {};
};
if (document.addEventListener) {
	document.addEventListener("DOMContentLoaded", init, false);
}
// for Internet Explorer (using conditional comments)
/*@cc_on @*/
/*@if (@_win32)document.write("<script id=__ie_onload defer src=javascript:void(0)><\/script>");
var script = document.getElementById("__ie_onload");
script.onreadystatechange = function() {
	if (this.readyState == "complete") {
		init();
	}
};
/*@end @*/

if (/WebKit/i.test(navigator.userAgent)) {
var _timer = setInterval(function() {
	if (/loaded|complete/.test(document.readyState)) {
		clearInterval(_timer); init();}}, 10);
};

window.onload = init;

window.onresize = function(){
  checkWindowWidth();
};

}; //end opera mini 4
