// JavaScript Document
function rand( min, max ) {
    if( max ) {
        return Math.floor(Math.random() * (max - min + 1)) + min;
    } else {
        return Math.floor(Math.random() * (min + 1));
    }
}

function increase(id, hoogte){
		/**/
		//alert(hoogte);
		var hoger = hoogte + 0.02;
		var iehoger = hoger*100;
		//var hoger = Number(document.getElementById(id).style.opacity) + 0.02;
		if(hoger<0.9){
			document.getElementById(id).style.opacity = hoger;
			document.getElementById(id).style.filter = 'alpha(opacity=' + iehoger + ')';
			functie = "increase('" + id + "'" + "," + hoger +")";
			setTimeout(functie,50);
		}
		
		
}

function swapFace(){
	var t;
	var aan = Array();
	var uit = Array();
	
	faces = document.getElementById('portretten').getElementsByTagName('img');
	for(i=0; i<faces.length; i++){
		//alert(faces[i].src);	
		if(faces[i].style.display == 'none'){
			uit.push(faces[i].id);
		}else{
			aan.push(faces[i].id);
		}
	}
	
	randaan = rand(0,aan.length-1);
	randuit = rand(0,uit.length-1);
	
	newsrc = document.getElementById(uit[randuit]).src;
	oldsrc = document.getElementById(aan[randaan]).src;
	newhref = document.getElementById(uit[randuit]).parentNode.getAttribute('href');
	oldhref = document.getElementById(aan[randaan]).parentNode.getAttribute('href');
	//alert(oldhref + ' en nieuw = ' + newhref); 
	
	//en nu de src van random aan en uit portret wisselen
	document.getElementById(uit[randuit]).src = oldsrc;
	document.getElementById(aan[randaan]).src = newsrc;
	document.getElementById(uit[randuit]).parentNode.setAttribute('href',oldhref);
	document.getElementById(aan[randaan]).parentNode.setAttribute('href',newhref);
	document.getElementById(aan[randaan]).style.opacity = 0;
	increase(aan[randaan],0);
	
	
	t=setTimeout("swapFace()",5000);
	
}

addLoadEvent(function(){ swapFace(); }); 


