/* ======== Constants ======== */

var PAGE_TRANSITIONS = true;


/* ======== Functions ======== */

function rnd(min, max) {
	return min + Math.floor(Math.random()*(max-min))
}

function navigateWithTransition(page) {
	// Hide the layout and then redirect
	$("body").fadeTo(400,0.0,function(){
		$(window).unload(function() {}); // Forces firefox to reload the page on browser back
		window.location.href = page;
	});
}

/* ======== DOM Ready ======== */

$(document).ready(function(){

	// Lazy load images
	$("img").lazyload({
	 effect      : "fadeIn"
	});
	
	if(PAGE_TRANSITIONS) {
	
		// Hide paper and contents
		var elems = $("body *").not("script").not("img");
		elems.fadeTo(0,0.0);
		
		// Hook all clicks for transition...
		$("a").click(function() {
			navigateWithTransition($(this).attr("href"));
			return false;
		});
		
	}
	
	/*$("p.image img").hover(function(){
		$(this).stop().fadeTo(400,1.0);
	},function(){
		$(this).stop().fadeTo(400,0.2);
	});*/
	
	
	
});


/* ======== All Resources Loaded ======== */

$(window).load(function() {
	
	if(PAGE_TRANSITIONS) {
		var elems = $("body *").not("script").not("img");
		var delay = 0;
		elems.each(function() {
			delay++;
			var elem = $(this);
			setTimeout(function() {
				elem.fadeTo(rnd(300,700),1.0);
			//},rnd(0,200));
			},delay*25);
		});
	}
	
});

