function newBanner() {
	if(totaal > 1) {
		old = document.getElementById('new').getElementsByTagName('img')[0].src.substr(-5, 1);
		n = old;
		while(n == old) {
			n = Math.floor((Math.random() * (totaal)) + 1);
		}
	document.getElementById('new').getElementsByTagName('img')[0].src = document.getElementById('new').getElementsByTagName('img')[0].src.substr(0, document.getElementById('new').getElementsByTagName('img')[0].src.length - 5) + n + '.jpg';
	}
	document.getElementById('new').opacity = '0';
	document.getElementById('new').filter = 'alpha(opacity=0)';
	n = 0;
	a = 0;
	scrollBanner();	
}
function scrollBanner() {
	if(a < 10) {
		a++;
		document.getElementById('new').style.opacity = a / 10;
		document.getElementById('new').style.filter = 'alpha(opacity=' + a * 10 + ')';
	}
	n -= 2;
	document.getElementById('new').getElementsByTagName('img')[0].style.top = n + 'px';
	if(n > 0 - document.getElementById('new').getElementsByTagName('img')[0].offsetHeight + 200) {
		setTimeout('scrollBanner();', 75);
	}
	else if (a == 10) {
		newBanner();
	}
}
function xmlrequest(url, target) {
  globalUrl = url;
  if (window.XMLHttpRequest) {
    req = new XMLHttpRequest();
  } else if (window.ActiveXObject) {
    req = new ActiveXObject("Microsoft.XMLHTTP");
  }
  if (req != undefined) {
    req.onreadystatechange = function() { xmlrequestDone(url, target); };
    req.open("GET", url, true);
    req.send("");
  }
}  
function xmlrequestDone(url, target) {
  if (req.readyState == 4) { // only if req is "loaded"
    if (req.status == 200) { // only if "OK"
      document.getElementById(target).innerHTML = req.responseText;
    } else {
      document.getElementById(target).innerHTML=" AJAX ERROR:\n"+ req.status + "\n" +req.statusText;
    }
  }
}
function openActiviteit(datum) {
	if(document.getElementById('alignContainer')) {
		document.body.removeChild(document.getElementById('alignContainer'));
	}
	menuBalkObj = document.createElement('div');
	menuBalkObj.id = 'activiteitMenuBalk';
	menuBalkObj.style.right = '0px';
	menuBalkObj.style.height = '20px';
	menuBalkObj.style.textAlign = 'right';
	menuBalkObj.style.position = 'relative';
	menuBalkObj.style.left = '0px';
	menuBalkObj.style.top = '0px';
	menuBalkObj.style.margin = '-10px';
	menuBalkObj.style.fontSize = '14px';
	menuBalkObj.innerHTML = '<span style=\"cursor:pointer;\">X</span>&nbsp;&nbsp;&nbsp;';
	vergrootImgObj = document.createElement('div');
	vergrootImgObj.id = 'vergrootImg';
	vergrootImgObj.style.position = 'absolute';
	vergrootImgObj.style.top = '30px';
	vergrootImgObj.style.left = '10px';
	vergrootImgObj.style.width = '400px';
	vergrootImgObj.style.height = '250px';
	vergrootImgObj.style.border = '0';
	vergrootImgObj.style.overflow = 'auto';
	alignImgObj = document.createElement('div');
	alignImgObj.id = 'alignContainer';
	alignImgObj.style.position = 'fixed';
	alignImgObj.style.top = '0px';
	alignImgObj.style.width = '100%';
	alignImgObj.style.height = '100%';
	alignImgObj.style.left = '0px';
	alignImgObj.style.zIndex = '9999';
	grootImgObj = document.createElement('div');
	grootImgObj.id = 'vergrootLayer';
	grootImgObj.style.position = 'relative';
	grootImgObj.style.top = '150px';
	grootImgObj.style.width = '0px';
	grootImgObj.style.height = '30px';
	grootImgObj.style.margin = 'auto';
	grootImgObj.style.overflow = 'hidden';
	grootImgObj.style.padding = '10px';
	grootImgObj.appendChild(menuBalkObj);
	grootImgObj.appendChild(vergrootImgObj);
	alignImgObj.appendChild(grootImgObj);
	document.body.appendChild(alignImgObj);
	document.getElementById('alignContainer').onclick = function() { activiteitSluiten(); }
	timer = 0;
	ivar = null;
	sluit2 = null;
	sluit = null;
	openActiviteitAnime();
	xmlrequest('/activiteiten.php?d=' + datum, 'vergrootImg');
}
function openActiviteitAnime() {
	if(ivar != "sluiten") {
		if(timer < 10) {
			timer++;
			document.getElementById('vergrootLayer').style.width = (document.getElementById('vergrootImg').offsetWidth / 10) * timer + 'px';
			setTimeout('openActiviteitAnime()', 75);
		}
		if(timer > 9 && timer < 20) {
			timer++;
			document.getElementById('vergrootLayer').style.height = (document.getElementById('vergrootImg').offsetHeight / 10) * (timer - 10) + 20 +'px';
			setTimeout('openActiviteitAnime()', 75);
		}
		if(timer > 19) {
				sluit2 = "sluit";
		}
	}
	else {
		activiteitSluiten('sluit');
	}
}
function activiteitSluiten(sluit) {
	if(document.getElementById('alignContainer')) {
		ivar = "sluiten";
		if(sluit == "sluit" || sluit2 == "sluit") {
			document.body.removeChild(document.getElementById('alignContainer'));
		}
	}	
}
function openVereniging(nr) {
	if(document.getElementById('alignContainer')) {
		document.body.removeChild(document.getElementById('alignContainer'));
	}
	menuBalkObj = document.createElement('div');
	menuBalkObj.id = 'activiteitMenuBalk';
	menuBalkObj.style.right = '0px';
	menuBalkObj.style.height = '20px';
	menuBalkObj.style.textAlign = 'right';
	menuBalkObj.style.position = 'relative';
	menuBalkObj.style.left = '0px';
	menuBalkObj.style.top = '0px';
	menuBalkObj.style.margin = '-10px';
	menuBalkObj.style.fontSize = '14px';
	menuBalkObj.innerHTML = '<span style=\"cursor:pointer;\">X</span>&nbsp;&nbsp;&nbsp;';
	vergrootImgObj = document.createElement('div');
	vergrootImgObj.id = 'vergrootImg';
	vergrootImgObj.style.position = 'absolute';
	vergrootImgObj.style.top = '30px';
	vergrootImgObj.style.left = '10px';
	vergrootImgObj.style.width = '400px';
	vergrootImgObj.style.height = '250px';
	vergrootImgObj.style.border = '0';
	vergrootImgObj.style.overflow = 'auto';
	alignImgObj = document.createElement('div');
	alignImgObj.id = 'alignContainer';
	alignImgObj.style.position = 'fixed';
	alignImgObj.style.top = '0px';
	alignImgObj.style.width = '100%';
	alignImgObj.style.height = '100%';
	alignImgObj.style.left = '0px';
	alignImgObj.style.zIndex = '9999';
	grootImgObj = document.createElement('div');
	grootImgObj.id = 'vergrootLayer';
	grootImgObj.style.position = 'relative';
	grootImgObj.style.top = '150px';
	grootImgObj.style.width = '0px';
	grootImgObj.style.height = '30px';
	grootImgObj.style.margin = 'auto';
	grootImgObj.style.overflow = 'hidden';
	grootImgObj.style.padding = '10px';
	grootImgObj.appendChild(menuBalkObj);
	grootImgObj.appendChild(vergrootImgObj);
	alignImgObj.appendChild(grootImgObj);
	document.body.appendChild(alignImgObj);
	document.getElementById('alignContainer').onclick = function() { verenigingSluiten(); }
	timer = 0;
	ivar = null;
	sluit2 = null;
	sluit = null;
	openVerenigingAnime();
	xmlrequest('/verenigingen.php?nr=' + nr, 'vergrootImg');
}
function openVerenigingAnime() {
	if(ivar != "sluiten") {
		if(timer < 10) {
			timer++;
			document.getElementById('vergrootLayer').style.width = (document.getElementById('vergrootImg').offsetWidth / 10) * timer + 'px';
			setTimeout('openVerenigingAnime()', 75);
		}
		if(timer > 9 && timer < 20) {
			timer++;
			document.getElementById('vergrootLayer').style.height = (document.getElementById('vergrootImg').offsetHeight / 10) * (timer - 10) + 20 +'px';
			setTimeout('openVerenigingAnime()', 75);
		}
		if(timer > 19) {
				sluit2 = "sluit";
		}
	}
	else {
		verenigingSluiten('sluit');
	}
}
function verenigingSluiten(sluit) {
	if(document.getElementById('alignContainer')) {
		ivar = "sluiten";
		if(sluit == "sluit" || sluit2 == "sluit") {
			document.body.removeChild(document.getElementById('alignContainer'));
		}
	}	
}
function vergrootFoto(url) {
	if(document.getElementById('alignContainer')) {
		document.body.removeChild(document.getElementById('alignContainer'));
	}
	menuBalkObj = document.createElement('div');
	menuBalkObj.id = 'activiteitMenuBalk';
	menuBalkObj.style.right = '0px';
	menuBalkObj.style.height = '20px';
	menuBalkObj.style.textAlign = 'right';
	menuBalkObj.style.position = 'relative';
	menuBalkObj.style.left = '0px';
	menuBalkObj.style.top = '0px';
	menuBalkObj.style.margin = '0px';
	menuBalkObj.style.fontSize = '14px';
	menuBalkObj.innerHTML = '<span style=\"cursor:pointer;\">X</span>&nbsp;&nbsp;&nbsp;';
	vergrootImgObj = document.createElement('img');
	vergrootImgObj.id = 'vergrootImg';
	vergrootImgObj.style.position = 'absolute';
	vergrootImgObj.style.top = '20px';
	vergrootImgObj.style.left = '0px';
	vergrootImgObj.style.border = '0';
	vergrootImgObj.style.margin = '10px';
	vergrootImgObj.src = '/album_stock/groot' + url;
	alignImgObj = document.createElement('div');
	alignImgObj.id = 'alignContainer';
	alignImgObj.style.position = 'absolute';
	alignImgObj.style.top = '0px';
	alignImgObj.style.width = '100%';
	alignImgObj.style.height = '100%';
	alignImgObj.style.left = '0px';
	alignImgObj.style.zIndex = '9999';
	grootImgObj = document.createElement('div');
	grootImgObj.id = 'vergrootLayer';
	grootImgObj.style.position = 'relative';
	grootImgObj.style.width = '0px';
	grootImgObj.style.height = '30px';
	grootImgObj.style.margin = '120px auto 0px auto';
	grootImgObj.style.overflow = 'hidden';
	grootImgObj.style.padding = '0px';
	grootImgObj.appendChild(menuBalkObj);
	grootImgObj.appendChild(vergrootImgObj);
	alignImgObj.appendChild(grootImgObj);
	document.body.appendChild(alignImgObj);
	document.getElementById('alignContainer').onclick = function() { fotoSluiten(); }
	timer = 0;
	ivar = null;
	sluit2 = null;
	sluit = null;
	openAnime();
}
function openAnime() {
	if(ivar != "sluiten") {
		if(timer < 10) {
			timer++;
			document.getElementById('vergrootLayer').style.width = (document.getElementById('vergrootImg').offsetWidth / 10) * timer + 20 +'px';
			setTimeout('openAnime()', 75);
		}
		if(timer > 9 && timer < 20) {
			timer++;
			document.getElementById('vergrootLayer').style.height = (document.getElementById('vergrootImg').offsetHeight / 10) * (timer - 10) + 40 +'px';
			setTimeout('openAnime()', 75);
		}
		if(timer > 19) {
				sluit2 = "sluit";
		}
	}
	else {
		fotoSluiten('sluit');
	}
}
function fotoSluiten(sluit) {
	if(document.getElementById('alignContainer')) {
		ivar = "sluiten";
		if(sluit == "sluit" || sluit2 == "sluit") {
			document.body.removeChild(document.getElementById('alignContainer'));
		}
	}	
}
function swapBG() {
	if(totaal > 1) {
		old = document.getElementById('new').src.substr(-5, 1);
		n = old
		while(n == old) {
			n = Math.floor((Math.random() * (totaal)) + 1);
		}
		o = 10;
		i = 0;
		document.getElementById('new').id = 'old';
		newImg = new Image();
		newImg.src = document.getElementById('old').src.substr(0, document.getElementById('old').src.length - 5) + n + '.jpg';
		newImg.id = 'new';
		newImg.style.opacity = 0;
		newImg.style.filter = 'alpha(opacity=0)';
		newImg.style.position = 'absolute';
		newImg.style.top = '0px';
		newImg.style.left = '0px';
		newImg.style.zIndex = '1';
		newImg.style.width = '900px';
		newImg.style.height = '500px';
		document.getElementById('content').appendChild(newImg);  
		fadeBGOut();
		fadeBGIn();	
	}
}
function fadeBGOut () {
	if(o > -1) {
		document.getElementById('old').style.filter = 'alpha(opacity=' + (o * 10) + ')';
		document.getElementById('old').style.opacity = o / 10;
		o--;
		setTimeout('fadeBGOut()', 75);
	}
	else {
		if(document.getElementById('old')) {
			document.getElementById('content').removeChild(document.getElementById('old'));
		}
	}
}
function fadeBGIn() {
	if(i < 11) {
		document.getElementById('new').style.filter = 'alpha(opacity=' + (i * 10) + ')';
		document.getElementById('new').style.opacity = i / 10;
		i++;
		setTimeout('fadeBGIn()', 75);
	}
	else {
		setTimeout('swapBG()', 10000);
	}
}
