window.addEvent('domready', function(){
	
	if($('intro_wrapper')){

		var blockAmount = 36;
		
		//afbeeldingen preloaden
		imageArr = new Array();
		for(x=0;x<blockAmount;x++){
			imageArr[x] = templateFolder + 'images/intro/' + (x+1) + '.jpg';
		}		
		imageArr[blockAmount] = templateFolder + 'images/intro/old_site.jpg';
		new Asset.images(imageArr, {
			onComplete: function(){ //afbeeldingen zijn geladen

				//intro achtergrond (wit)
				$('intro_wrapper').setStyle('height', window.getScrollHeight() + 'px');
								
				//oude site positioneren
				windowHeight = window.getHeight();
				$('old_site').setStyle('margin-top', (windowHeight/2) - 225 + 'px');
				
				//achtergrondafbeelding instelling van oude site
				$('old_site').setStyle('background-image', 'url(' + templateFolder + 'images/intro/old_site.jpg)');

				var blocks = new Array();
				for(x=0;x<blockAmount;x++){
					blocks[x] = x + 1;
				}
				blocks = shuffle(blocks);
				counter = 0;
				var addBlock = function(){
					if(counter <= (blockAmount - 1)){
						$('block_' + blocks[counter]).setStyle('opacity', 0);
						$('block_' + blocks[counter]).fade(1);
					}else {
						$clear(periodical);
						$('old_site').setStyle('background', '#FFFFFF');
						$('intro_wrapper').set('tween', {
							onComplete: function(e) {
									$(e.id).set('tween', { onComplete: Class.empty });
									$('intro_wrapper').destroy();
									$('transition_wrapper').destroy();
								}
							});
						$('intro_wrapper').tween('opacity', '0');			
					}
					counter++;
				}
				periodical = addBlock.periodical(100);					
			}
		});
	}
	
}).addEvent('resize', function(){	
	if($('intro_wrapper')){
		//oude site positioneren
		windowHeight = window.getHeight();
		$('old_site').setStyle('margin-top', (windowHeight/2) - 225 + 'px');	
		
	}
});

shuffle = function(o){
	for(var j, x, i = o.length; i; j = parseInt(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);
	return o;
};
