
function fit_background() {
	
	$('#fold-img').height($('#body').position().top + $('.intro').outerHeight());
	var offset = $(window).width() / 2 - 495 + 72;
	$('.work-info').css('padding-left', offset + 'px');
	$('.work-info').css('margin-left', '-' + offset + 'px');
	
	
	// winratio = $(window).width() / $(window).height();
	winratio = $(window).width() / $('#fold-img').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');
		// $('#status').text('winratio > imgratio ' + winratio);
	} else {
		// newratio = $(window).height() / imgheight;
		newratio = $('#fold-img').height() / imgheight;
		newwidth = Math.round(imgwidth * newratio);
		$('#background').width(newwidth);
		// $('#background').height($(window).height());
		$('#background').height($('#fold-img').height());
		// $('#background').css('left', Math.round(($(window).width() / 2) - (newwidth / 2)) + $(window).scrollLeft() + 'px');
		// $('#status').text('winratio < imgratio (else) ' + winratio + ' < ' + imgratio);
	}
	
	$('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());
		}
	});
	
	$('#overlay').height($('.edge').height());
}
		
$(window).load(function () {		
								 
	// Clear div following last div
	// $('div.last').addClass('clear');
	// $('div.last + div:not(.feature)').addClass('clear');		
									
	fit_edges();
	$(window).resize(fit_edges);
								 
	imgwidth = $('#background').width();
	imgheight = $('#background').height();
	imgratio = imgwidth / imgheight;
	fit_background();
	$(window).resize(fit_background);
	
});
		

