//http://nocturne.net.nz/webdev/imgfade.php
//zie aanvulling in blog: function initImage is aangepast

document.write("<style type='text/css'>.hideimg {visibility:hidden;}</style>");

function initImage() {

	i = 1;

	while (true) {

		imageId = 'theimg' + i;

		obj = document.getElementById(imageId);

		if (obj == null) break;

		setOpacity(imageId, 0);

		obj.style.visibility = "visible";

		fadeIn(imageId);
		
		i++;

	}

}
function initImage_FadeOut() {
	var i = 1;
	var imageId;
	
	while (true) {
		imageId = 'theimgfadeout' + i;
		obj = document.getElementById(imageId);
		if (obj == null) break;

		setOpacity(imageId, 100);
		obj.style.visibility = "visible";
		fadeOut(imageId);

		i++;
	}
}
delay=12;
 
function fadeIn(objId) {
	
	opacity = 1;
	if (document.getElementById) {
		while (opacity <= 100) {
			window.setTimeout("setOpacity('"+objId+"',"+opacity+")", delay);
			opacity += 1;
			delay += 10; // modify to change fade speed
		}
	}
}

//***********
//fade out functions
function fadeOut(objId) {
	var delay_speed = 40; // modify to change fade speed
	opacity = 140; //99 to start fading immediately;
	if (document.getElementById) {
		while (opacity >= 0) {
			if (opacity <= 100) {
				window.setTimeout("setOpacity('"+objId+"',"+opacity+")", delay);
			}
			opacity -= 1;
			delay += delay_speed;
		}
		if (opacity <= 0) {
			delay += delay_speed;
			//after fading out, hide the layer that contains the image
			window.setTimeout("HideImgFadeObj();", delay);
		}
	}
}
function HideImgFadeObj() {
	var obj = document.getElementById("verhuisdoos");
	if (obj == null) return;
	
	//enable links below this div
	obj.style.display = "none";
}
//***********

function setOpacity(objId, opacity) {
	if (document.getElementById) {
		obj = document.getElementById(objId);
		opacity = (opacity == 100)?99.999:opacity;
		// IE/Win
		obj.style.filter = "alpha(opacity:"+opacity+")";
		// Safari<1.2 Konqueror
		obj.style.KHTMLOpacity = opacity/100;
		// Older Mozilla and Firefox
		obj.style.MozOpacity = opacity/100;
		// Safari 1.2, newer Firefox and Mozilla, CSS3
		obj.style.opacity = opacity/100;
	}
}

//window.onload = function() {initImage()}

//we should leave what was sei in window.onload earlier and  append our function(s) to it
var PreImgFadeOnload =(window.onload)? window.onload : function(){};
window.onload = function(){PreImgFadeOnload(); initImage(); initImage_FadeOut();}

