$(document).ready(function() {

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

function background() {
	var availableWidth = $(window).width();
	var availableHeight = $(window).height();
	var imageHeight = 1048;
	var imageWidth = 1600;
	var curWidth;
	var curHeight;
	//if(imageHeight < availableHeight || imageWidth < availableWidth) {
		var percWidth = Math.floor((availableWidth * 100) / imageWidth);
		var percHeight = Math.floor((availableHeight * 100) / imageHeight);
		if(percWidth > percHeight) {
			curWidth = availableWidth;
			curHeight = resizeImage(imageWidth, imageHeight, availableWidth, 0, 'returnheight');
		} else if(percWidth < percHeight) {
			curHeight = availableHeight;
			curWidth = resizeImage(imageWidth, imageHeight, 0, availableHeight, 'returnwidth');
		}
	//} else {
	//	curHeight = imageHeight;
	//	curWidth = imageWidth;
	//}
	$('#img').data('resized', true);
	$('#img').width(curWidth);
	$('#img').height(curHeight);
}
function resizeImage (w, h, nw, nh, coord) {
	if(coord == 'returnheight')	{
		var newH = Math.floor((h * nw) / w);
		return newH;
	} else if(coord == 'returnwidth') {
		var newW = Math.floor((w * nh) / h);
		return newW;
	}
}


