$j = jQuery.noConflict();
$j(function(){
	var mainHeight = $j('#main').height();
	autoHeight = function(){
		var bodyHeight = Math.max(document.documentElement.clientHeight,document.body.scrollHeight);
		var imgHeight = $j('.background-img').height();
		var maxHeight = Math.max(bodyHeight, imgHeight) - 518;
		$j('#main').height(maxHeight < mainHeight ? mainHeight:maxHeight);
		if(imgHeight < $j('#wrapper').height()) {
			$j('.background-img').height($j('#wrapper').height()+6);
		}
	}
	
	$j(window).resize(function(){
		autoHeight();
	});
	
	autoHeight();
});
