var size = null;

$(window).load(function(){
	size = getSize();
	$(window).trigger('resize')
});

$(window).resize(function() {
	resizeImage()
});

function resizeImage() {
	var screenWidth = $(window).width();
	var screenHeight = $(window).height();
	
	var ratio = size[0] / size[1];

	var windowRatio = screenWidth / screenHeight;	
				
	if (windowRatio <= ratio) {
		$(".backimg").attr('width', screenHeight * ratio);
		$(".backimg").attr('height', screenHeight);
	} else {
		$(".backimg").attr('width', screenWidth);
		$(".backimg").attr('height', (screenWidth) / ratio);
	}
}

function getSize() {
	return new Array($("#back").width(), $("#back").height());
}

