var animationIntervalId = null;
var animQ = [];
var animatedElements = ["logo","about","blog","articles","portfolio", "personal"];

window.onload = handleWindowOnLoad;

function handleWindowOnLoad(){
	for(var i = 0; i < animatedElements.length; i++){
		var anim = new AnimatedElement(document.getElementById(animatedElements[i]));
		anim.setAlpha(0);
		anim.effects.push(new AnimEffect(FADE_EFFECT, anim, 100, 30/(i+1)));
		animQ.push(anim);
	}
	initAnimation();
}

function initAnimation(){
	clearInterval(animationIntervalId);
	animationIntervalId = setInterval(doAnimation, 50);
}

function doAnimation(){
	var i = 1;
	if(i > 2){
		i = 2;
	}
	
	while(i){
		if(animQ[--i].effects[0].update()){
			continue;
		}
		animQ.splice(i, 1);
		if(animQ.length < 1){
			clearInterval(animationIntervalId);
		}
	}
}