﻿window.onload = laadpag;

var isIE = (navigator.appName.indexOf("Microsoft") != -1 && navigator.appVersion.indexOf("Windows") > -1)+1-1;
if (isIE) document.execCommand("BackgroundImageCache", false, true);

var objBody;
var hasFlash = function(){
	var nRequiredVersion = 8;
	if(isIE){
		document.write('<script language="VBScript"\> \non error resume next \nhasFlash = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash." & ' + nRequiredVersion + '))) \n</script\> \n');
		if(window.hasFlash != null){ return window.hasFlash;};
	};
	if(navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"] && navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin){
		var flashDescription = (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]).description;
		var vr = parseInt(flashDescription.charAt(flashDescription.indexOf(".") - 1)); if (vr < 4) vr += 10;	
		return vr >= nRequiredVersion;
	};
	return false;
}();
if (isIE){document.write('<style type="text/css">#waas{height:expression(document.body.offsetHeight);}</style>')}
if (hasFlash){document.write('<style type="text/css">#xtitel{color:white;} .submenu{color:black} #hoofdmenu, .submenu a{visibility:hidden !important} .noflash{display:none}</style>')}
document.write('<style type="text/css">.slideshow div, #objnav{display:none}</style>');

function laadpag(){
	if (document.getElementsByTagName){
		objBody = document.getElementsByTagName("body").item(0);
		
		//if (eId('fh')) {homekopjes()};
		if (hasFlash) {
			if (eId('hoofdmenu')) menu();
			//titels();
			av();
		};
		slideshow(); imglinks();
		formframe();
		tijdbalk(); iframe(); zetflash();

		maxb = 16; voorv = '';
		if (objBody.className=='museumethiek') {maxb = 3; voorv = 'museumethiek';}
		var bg = Math.round(maxb*Math.random()); if (bg==0) bg=3; if (bg<10) bg = '0' + bg;
		if (eId('wrapper')) eId('wrapper').style.backgroundImage = 'url(/grafiek/rond/' + voorv + bg + '.jpg)';
		if (eId('objnav')) eId('onder').firstChild.innerHTML = eId('objnav').innerHTML;

	}	
}

function av(){
	if (eId('av')){
			ht = eId('av').offsetHeight; if (ht < 20) ht = 320;
			wt = eId('av').offsetWidth; if (wt < 350) ht = 350;
			var ti = eId('av').title;
			if (ti.indexOf('youtube') > 1) {
				eId('av').innerHTML = flash(ti.replace('watch?v=','v/'),'100%', ht, '#000000', '', '', '');
			} else {			
			
			var fv = 'file=' + ti + '&image=' + ti.replace('.flv','') + '.jpg&height='+ ht + '&width=' + wt + '&backcolor=0x000000&frontcolor=0xFFFFFF&lightcolor=0xD90000&screencolor=0x000000';
			if (ti.indexOf('.xml') > 1) {fv += '&thumbsinplaylist=true&standalone=yes&displayheight=' + (ht-100);}
			eId('av').innerHTML = flash("/grafiek/mediaplayer.swf", '100%', '100%', '#000000', '', fv, '');
			}
			
			eId('av').title = '';
			
	}
}

function titels(){
	if (eId('titel')){
	titw = "100%";
	if (eId('middenkolom')){titw = "320"; }
	tit = eId('titel').innerHTML;
	tith = eId('titel').offsetHeight;
	eId('titel').innerHTML = '<span>' + tit + '</span>' + flash('/grafiek/titel.swf', titw, tith, '', 'transparent', "tekst=<b>" + tit + "</b>");
	}
}

function formframe(){
		//iframe voor formulier
	if (eId('postform')){
		objIframe = document.createElement("div");
		objIframe.innerHTML='<iframe name="posttarget" style="visibility:hidden" width="0" height="0"></iframe>';
		document.getElementsByTagName("body").item(0).appendChild(objIframe);
	}	
}

function imglinks(){
	var anchors = document.getElementsByTagName('a');
		for (var i=0; i<anchors.length; i++){
			var anchor = anchors[i];
			if (anchor.getAttribute('href')){
				if (anchor.getAttribute('href').toLowerCase().match('.jpg') && anchor.getAttribute('target') != '_blank'){
				
				anchor.onclick = function () {groot(this); return false;}
				anchor.firstChild.title = '' + anchor.title;
			}
		}
		}

	anchors = document.getElementsByTagName('area');
		for (var i=0; i<anchors.length; i++){
			var anchor = anchors[i];
			if (anchor.getAttribute('href')){
				if (anchor.getAttribute('href').toLowerCase().match('.jpg')){
				anchor.onclick = function () {groot(this); return false;}
				//anchor.firstChild.title = '' + anchor.title;
			}
		}
		}

}




function dis(tf){
	if (tf){
		eId('meer').style.display='none';
		eId('meerlink').onclick = function(){
			dis(false); eId('meer').style.display='block'; this.style.display='none'; return false;}
	}
	if (eId('meerafd')) eId('meerafd').disabled = tf;
	var inps = eId('meer').getElementsByTagName('input');
	for (var i=0; i<inps.length; i++){
		inps[i].disabled = tf;
	}	
}


function homekopjes(){
	fv = '';
	for (var i=1; i<4; i++){
		fv += '&t' + i + '=' + prepT(eId('t' +i).innerHTML);
	}
	eId('fh').innerHTML = flash('/grafiek/homeblokken.swf', 800, 30, '', '', fv);	
}

function prepT(str){
	return escape('<p align="center"><b>' + str + '</b></p>');
}

function menu(){
	fv = '';
	for (var i=1; i<8; i++){
	  if (eId('submenu' +i)){
		tmp = eId('submenu' +i).innerHTML;
		tmp = tmp.replace(/\|/g, '   |    ');
		tmp = tmp.replace(/target=_blank/g, 'target="_blank"');
		tmp = '<p align="center">' + tmp + '</p>';
		fv += '&s' + i + '=' + escape(tmp);
		fv = fv.replace(/\%E9/g, 'é');
		if (eId('submenu' +i).className.indexOf('aan') > 1){fv += '&sel=m' + i};
	  }
	}
	
	var objMenuflash = document.createElement("div");
	objMenuflash.setAttribute('id','menuflash');
	objBody.appendChild(objMenuflash);
	subsite = objBody.className.split(' ')[0];
	if (subsite == 'home') subsite = '';
	eId('menuflash').innerHTML = flash('/grafiek/menu' + subsite + '.swf', 792, 80, '', 'transparent', fv);	

	
}

function reageer(par, subj, mail){
	if (eId('postform')){
		eId('postform').onderwerp.value = subj;
		eId('postform').cf_Parent.value = par;
		eId('postform').cf_Cc.value = mail;
	}
}


function flash(movie, w, h, bg, wm, flashvars, bas){
	if (isIE){
		return '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" id="'+movie+'" width="'+ w + '" height="' + h + '"><param name="movie" value="' + movie + '" /><param name="FlashVars" value="' + flashvars + '" /><param name="quality" value="high" /><param name="menu" value="false" /><param name="wmode" value="' + wm + '" /><param name="bgcolor" value="' + bg + '" /><param name="base" value="' + bas + '" /><param name="allowfullscreen" value="true" /></object>';
	} else {
		return '<embed src="' + movie + '" quality="high" wmode="' + wm + '" bgcolor="' + bg + '" menu="false" width="'+ w + '" base="' + bas + '" height="'+ h + '" FlashVars="' + flashvars + '" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" allowfullscreen="true" />';}
}

function groot(welke){
	var alt = ''
	if (welke.firstChild) alt = welke.firstChild.alt;
	if (welke.alt) alt = welke.alt;
	ghtm = '<div id="bijschrift"><a id="sluit" href="javascript:sluitpopup()"></a>' + alt + '</div>';
	if (window.zfmaat){
		ghtm += '<div style="' + zfmaat + '" id="breedste">' + flash('/grafiek/ZoomifyDesignViewer.swf', '100%', '100%', '#000000', '', 'zoomifyXMLPath=/grafiek/ZoomifyDesignViewer.xml&zoomifyNavigatorVisible=0&zoomifyImagePath=' + zfpad, '/') + '</div>'; 
	} else {
		ghtm += '<img onload="pw()" id="breedste" src="' + welke.href + '"/>';
	}
	popup(ghtm);
}

function topstuk(id){
	popup('<iframe id="breedste" src="/collectie/topstukken?altTemplate=rmo-tijdbalk&ObjectID=' + id + '&iframe=1" width="800" height="496" frameborder="0"></iframe>');	
}


function popup(html){
	if (eId('av')){eId('av').style.visibility='hidden';}
	window.scroll(0, 0);
	if (!eId('popupwrap')) {
			var objBody = document.getElementsByTagName("body").item(0);
			var objOverlay = document.createElement("div");
			objOverlay.setAttribute('id','waas');
			if (!isIE){objOverlay.style.height = (objBody.offsetHeight) + 'px';}
			objBody.appendChild(objOverlay);

			var objOverlay = document.createElement("div");
			objOverlay.setAttribute('id','popupwrap2');
			objBody.appendChild(objOverlay);
			eId('popupwrap2').innerHTML = '<table id="popupwrap"><tr><td align="center"><div id="popup"></div></td></tr></table>';
		}
		eId('popup').innerHTML = html;
		eId('waas').style.display='block';
		if (isIE) {eId('popupwrap').style.display='block'; document.onkeydown = terugtoets;} 
		else {eId('popupwrap').style.display='table'; document.onkeypress = terugtoets;}
		pw();
		
}

function pw(){eId('popup').style.width = eId('breedste').clientWidth + 'px';}

function terugtoets(e) {
  if(!e) e=window.event;
  key = e.keyCode ? e.keyCode : e.which;
  if (eId("popupwrap").style.display != 'none' && (key==8 || key==32 || key==37)){
  sluitpopup();return false;}
}


function sluitpopup(){
	if (eId('popup')) {
		if (eId('av')){eId('av').style.visibility='visible';}
		eId('waas').style.display='none';
		eId('popupwrap').style.display='none';	
	}
}

function tijdbalk(){
	if (eId('tijdbalkvak') && hasFlash) {
		e = eId('tijdbalkvak');
		vars =  (e.title + '|').split('|');
		e.className = 'tijdbalkvak';
		var objBody = document.getElementsByTagName("body").item(0);
		e.innerHTML = flash('/tijdbalk/tijdbalk.swf', '100%', '100%', '', '', 'jaar=' + vars[0] + '&nr=' +vars[1], '/tijdbalk/');			
	}
}

function iframe(){
	if (eId('iframe')) {
		e = eId('iframe');
		e.className = 'tijdbalkvak';
		eId('onder').style.display='none';
		e.innerHTML='<iframe height="100%" width="100%" src="' + e.title + '" frameborder="0" border="none"></iframe>';	
	}
}


function zetflash(){
	if (eId('flash')) {
		e = eId('flash');
		e.innerHTML = flash('/grafiek/' + e.title + '.swf', '100%', '100%', '', '', '', '/');
	}
}


function slideshow(){
	if  (eId('beeldvak')){ 
	if (eId('beeldvak').className=='slideshow'){
		var beelden = eId('beeldvak').getElementsByTagName('div');
		for (var i=0; i<beelden.length; i++){
			var html = '<span class="hoeveelste"><a id="volgendbeeld" ';
			if (i+1<beelden.length) {html += 'href="javascript:toonbeeld(' + (i+1) + ')"';} else {html += 'style="background:0"';}
			html += '></a><a id="vorigbeeld" ';
			if (i > 0) {html += 'href="javascript:toonbeeld(' + (i-1) + ')"';} else {html += 'style="background:0"';}
			
			if (window.location.href.indexOf('english') < 0)
				{html += '></a>Afbeelding ' + (i+1) + ' van ' + beelden.length;}
			else
				{html += '></a>Image ' + (i+1) + ' of ' + beelden.length;}
			
			beelden[i].innerHTML = html + '</span>' + beelden[i].innerHTML;
			}
		try{ eId('beeldvak').firstChild.style.display='block'; } catch(e){}
	}
	}
}

function toonbeeld(nr){
	var beelden = eId('beeldvak').getElementsByTagName('div');
	for (var i=0; i<beelden.length; i++){
		if (i != nr) {beelden[i].style.display='none';}
		else {beelden[i].style.display='block';}	
	}
}


function tijdbalk2(){
	tijdbalkWindow = window.open('/tijdbalk/tijdbalk.htm','venster','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=1,width=' + screen.availWidth + ',height=600,copyhistory=0,left=0,top=0,screenX=0,screenY=0');
	if (tijdbalkWindow != null) tijdbalkWindow.focus();
}

function eId(w){return document.getElementById(w);}

function zet(str){document.write(str);}

var url = window.document.location.toString();
var title = window.document.title;

function fav(){
	if (isIE) {window.external.AddFavorite(url,title)} else {alert('Sleep het aangeklikte icoontje naar de bookmark-balk van uw browser!')}
}

function sociaal(url2){
	if (url2 != '') url = url2;
	var r = '';
	var favtit = "voeg toe aan favorieten"; if (!isIE) favtit = "sleep naar bookmarks";
	r += '<div id="alg">';
	r += '<a href="/actueel/rss" title="abonneren op rss feed"></a>';	
	r += '<a href="mailto:?subject=' + encodeURI(title) + '&amp;body=' + encodeURI(url) + '" id="mail" title="doorsturen per e-mail"></a>';
	r += '<a href="' + url + '" onclick="fav(); return false;" id="fav" title="' + favtit + '"><span>' + title + '</span>&nbsp;&nbsp;&nbsp;&nbsp;</a>';
	r += '<a target="_blank" href="http://www.delicious.com/post?url=' + escape(url) + '&title=' + encodeURI(title) + '" title="Delicious"></a>';
	r += '<a target="_blank" href="http://twitter.com/share?text=' + encodeURI(title) + '&url=' + encodeURI(url) + '" title="Twitter"></a>';				
	r += '<a target="_blank" href="http://www.hyves.nl/profilemanage/add/tips/?name=' + encodeURI(title) + '&text=' + encodeURI(url) + '&type=12" title="Hyves"></a>';		
	r += '<a target="_blank" href="http://www.google.com/buzz/post?url=' + encodeURI(url) + '" title="Google Buzz"></a>';
	r += '<a target="_blank" href="http://favorites.live.com/quickAdd.aspx?url=' + encodeURI(url) + '&title=' + encodeURI(title) + '" title="Msn/Live Favorite"></a>';	
	r += '<a target="_blank" href="http://www.facebook.com/sharer.php?u=' + encodeURI(url) + '&t=' + encodeURI(title) + '" title="Facebook"></a>';	
	r += '</div>';
	document.write(r);
}

var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-18573759-1']);
_gaq.push(['_trackPageview']);

(function() {
	var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
