	/**
 * Resizes the background image to the current size
 */
$(document).ready(function() {
	var theWindow = $(window), $bg = $("#bg");

	function resizeBg() {
		var aspectRatio = $bg.width() / $bg.height();
		
		if ((theWindow.width() / theWindow.height()) < aspectRatio) {
			$bg.removeClass().addClass('bgheight');
		} else {
			$bg.removeClass().addClass('bgwidth');
		}
	}

	theWindow.resize(function() {
		resizeBg();
	});
	
	// Initial sizing
	function checkIfImageIsLoaded() {
		if($bg.width()) {
			resizeBg();
		} else {
			setTimeout(checkIfImageIsLoaded, 10);
		}
	}
	
	// Initial resize
	checkIfImageIsLoaded();
});

