$(function() {
	var startheight = 1000;
	var startwidth = 1400;
	var imagewidth = 0;
	var imageheight = 0;				
	
	//$('#bg_image img').load(function() {				
		imagewidth = $(this).width();			
		imageheight = $(this).height();
		$('#bg_image').css('position','fixed');
		resizer(imagewidth,imageheight);
	//});
	
	function resizer(imagewidth,imageheight) {
		
		//Define image ratio								
		var ratio = startheight/startwidth;
		var browserwidth = $(window).width();
		var browserheight = $(window).height();
		var offset;
		var bg_image = '#bg_image img';				
		
		//Resize image to proper ratio
		if ((browserheight/browserwidth) > ratio){
		    $('#bg_image').height(browserheight);
		    $('#bg_image').width(browserheight / ratio);
		    $('#bg_image').children().height(browserheight);
		    $('#bg_image').children().width(browserheight / ratio);
		} else {
		    $('#bg_image').width(browserwidth);
		    $('#bg_image').height(browserwidth * ratio);
		    $('#bg_image').children().width(browserwidth);
		    $('#bg_image').children().height(browserwidth * ratio);
		}
		
		
		//$(bg_image).css('left', ((browserwidth - $(bg_image).width())/2));
	}
	
	function setPatternHeight() {
		var bodyh = $('body').height();
		var contenth = $('#content').height();
		
		if (contenth > bodyh) {
			$('#bg_pattern').height(contenth);
		}else{
			$('#bg_pattern').height(bodyh);
		}
			
	}
	
	$(window).resize(function() {
		//Gather browser and current image size
		imagewidth = $('#bg_image').width();			
		imageheight = $('#bg_image').height();				
		resizer(imagewidth,imageheight);
		setPatternHeight();
	});
	
	setPatternHeight();
});
