/**
 * @author petergoes
 */

(function(){
	var counter = 0;
	var images = [];
	
	jQuery(document).ready(loadImages);
	
	function loadImages(){
		images.push(new Image());
		images[0].onload = imageLoaded;
		images[0].src = "/media/images/backgrounds/parallax-background/front.png";
		
		images.push(new Image());
		images[1].onload = imageLoaded;
		images[1].src = "/media/images/backgrounds/parallax-background/middle.png";
		
		images.push(new Image());
		images[2].onload = imageLoaded;
		images[2].src = "/media/images/backgrounds/parallax-background/back.png";
	}
	
	function display(){
		jQuery(document.body).prepend('<div id="parallax"><img src="/media/images/backgrounds/parallax-background/front.png" style="width:2400px; height:540px"><img src="/media/images/backgrounds/parallax-background/middle.png" style="width:2200px; height:540px"><img src="/media/images/backgrounds/parallax-background/back.png" style="width:2000px; height:540px"></div><div id="parallax-hitarea">&nbsp;</div>');

		jQuery('#parallax').jparallax({
			mouseport: jQuery('#parallax-hitarea'),
			takeoverFactor: .985,
			takeoverThresh: 0.02
		})
	}
	
	function imageLoaded(){
		counter++;
		if(counter == images.length){
			display();
		}
	}
})();