
function fit_background() {
	
	winratio = $(window).width() / $(window).height();
	if (winratio > imgratio) {
		newratio = $(window).width() / imgwidth;
		newheight = Math.round(imgheight * newratio);
		$('#background').height(newheight);
		$('#background').width($(window).width());
		// $('#background').css('top', Math.round(($(window).height() / 2) - (newheight / 2)) + $(window).scrollTop() + 'px');
	} else {
		newratio = $(window).height() / imgheight;
		newwidth = Math.round(imgwidth * newratio);
		$('#background').width(newwidth);
		$('#background').height($(window).height());
		// $('#background').css('left', Math.round(($(window).width() / 2) - (newwidth / 2)) + $(window).scrollLeft() + 'px');
	}
	
	$('body').css('visibility','visible');
	
}

function fit_edges() {
	
	var page_left = $(window).width() / 2 - 495;
	$('.edge.left').css('left', page_left + 'px');
	$('.edge.right').css('left', page_left + 989 + 'px');
	var page_height = $('#body').position().top + $('#body').outerHeight();
	$('.edge').each(function() {
		if (page_height > $(window).height()) {
			$(this).height(page_height);
		} else {
			$(this).height($(window).height());
		}
	});
	
}

$(document).ready(function() {					
									
	fit_edges();
	$(window).resize(fit_edges);
	
	$('h4:first-child, p:first-child').addClass('first');
	$('p:last-child').addClass('last');
	
	$('.tile a.show').click(function(event) {
		event.preventDefault();
		if ($(this).hasClass('show_inner')) {
			$(this).closest('.cover').css('visibility', 'hidden');
			$(this).closest('.cover').siblings('.inner').css('visibility', 'visible');
		} else if ($(this).hasClass('show_cover')) {
			$(this).closest('.inner').css('visibility', 'hidden');
			$(this).closest('.inner').siblings('.cover').css('visibility', 'visible');
		}
	});
	
});

$(window).load(function () {
								 
	imgwidth = $('#background').width();
	imgheight = $('#background').height();
	imgratio = imgwidth / imgheight;
	fit_background();
	$(window).resize(fit_background);
	
});

