﻿var schuifSnelheid = 930;	// hogere waarde = sneller
var pauze = 2;				// lagere waarde = sneller
var openItem = false;
var actiefItem = false;
var schuivenBezig = false;

function tonenVerbergen(e,invoerId) {
	if(schuivenBezig)return;
	schuivenBezig = true;
	if(!invoerId)invoerId = this.id;
	invoerId = invoerId + '';
	var getalId = invoerId.replace(/[^0-9]/g,'');
	var antwoordDiv = document.getElementById('titel' + getalId);
	openItem = false;
	if(!antwoordDiv.style.display || antwoordDiv.style.display=='none'){		
		if(actiefItem &&  actiefItem!=getalId){			
			openItem = getalId;
			schuifInhoud(actiefItem,(schuifSnelheid*-1));}
		else{
			antwoordDiv.style.display='block';
			antwoordDiv.style.visibility='visible';
			schuifInhoud(getalId,schuifSnelheid);}}
		else{
		schuifInhoud(getalId,(schuifSnelheid*-1));
		actiefItem = false;}}

function schuifInhoud(invoerId,richting){
	var object =document.getElementById('titel' + invoerId);
	var inhoudObject = document.getElementById('tekst' + invoerId);
	hoogte = object.clientHeight;
	if(hoogte==0)hoogte = object.offsetHeight;
	hoogte = hoogte + richting;
	doorloopFunctieOpnieuw = true;
	if(hoogte>inhoudObject.offsetHeight){
		hoogte = inhoudObject.offsetHeight;
		doorloopFunctieOpnieuw = false;}
	if(hoogte<=1){
		hoogte = 1;
		doorloopFunctieOpnieuw = false;}
	object.style.height = hoogte + 'px';
	var topPos = hoogte - inhoudObject.offsetHeight;
	if(topPos>0)topPos=0;
	inhoudObject.style.top = topPos + 'px';
	if(doorloopFunctieOpnieuw){
		setTimeout('schuifInhoud(' + invoerId + ',' + richting + ')',pauze);}
	else{
	if(hoogte<=1){
		object.style.display='none'; 
		if(openItem && openItem!=invoerId){
			document.getElementById('titel' + openItem).style.display='block';
			document.getElementById('titel' + openItem).style.visibility='visible';
			schuifInhoud(openItem,schuifSnelheid);}
		else{schuivenBezig = false;}}
	else{actiefItem = invoerId; schuivenBezig = false;}}}

function init(){
	var divs = document.getElementsByTagName('DIV');
	var divTeller = 1;
	for(var nr=0;nr<divs.length;nr++){
		if(divs[nr].className=='vraag'){
			divs[nr].onclick = tonenVerbergen;
			divs[nr].id = 'startVraag'+divTeller;
			var antwNr = divs[nr].nextSibling;
			while(antwNr && antwNr.tagName!='DIV'){
				antwNr = antwNr.nextSibling;}
			antwNr.id = 'titel'+divTeller;	
			inhoudDiv = antwNr.getElementsByTagName('DIV')[0];
			inhoudDiv.style.top = 0 - inhoudDiv.offsetHeight + 'px'; 	
			inhoudDiv.className='antwoordInhoud';
			inhoudDiv.id = 'tekst' + divTeller;
			antwNr.style.display='none';
			antwNr.style.height='1px';
			divTeller++;}}}
window.onload = init; // eventueel te verwijderen en in body-tag te plaatsen
