$(window).load(function() {    
	var theWindow = $(window);
	var $bg = $("#mainImage");
	var aspectRatio = $bg.width() / $bg.height();

	function resizeBg() 
	{
		if ( (theWindow.width() / theWindow.height()) < aspectRatio ) {
			$bg.removeClass().addClass('miWidth');
			$bg.css('top',(theWindow.height()/2 - ($bg.height()) / 2) + "px");
			$bg.css('left',(theWindow.width() / 2 - ($bg.width()) / 2) + "px");
			
		} else {
			$bg.removeClass().addClass('miHeight');
			$bg.css('left',(theWindow.width()/2 - ($bg.width()) / 2) + "px");
			$bg.css('top',(theWindow.height()/2 - ($bg.height()) / 2) + "px");
		}
	}

	theWindow.resize(function() {
		resizeBg();
	}).trigger("resize");
	$("#mainImage").fadeTo(600,1.0);
});
