var bgDivCover = bgDivPhoto = 0;
var imageRatio = 1.5; /* 1.5 for 3:2 or 1.33333 for 4:3 */
var targetWidth = targetHeight = targetTopPos = targetLeftPos = 0;
var currentWidth = currentHeight = currentTopPos = currentLeftPos = 0;
function resizeImage() {
	bodyElements = document.getElementsByTagName("body");
	bgDivCover = document.getElementById("cover");
	bgDivPhoto = document.getElementById("photo");
	var winWidth = bgDivCover.width
	var winHeight = bgDivCover.height;
	var winRatio = winWidth / winHeight;
	if (winRatio >= imageRatio) {
		targetWidth = winWidth;
		targetHeight = Math.round(winWidth / imageRatio);
		targetLeftPos = 0;
		targetTopPos = Math.round((winHeight - targetHeight) / 2);
	}
	else {
		targetWidth = Math.round(winHeight * imageRatio);
		targetHeight = winHeight;
		targetLeftPos = Math.round((winWidth - targetWidth) / 2);
		targetTopPos = 0;
	}
	currentWidth = bgDivPhoto.width;
	currentHeight = bgDivPhoto.height;
	currentTopPos = 0;
	currentLeftPos = 0;
	if (targetWidth > currentWidth) currentLeftPos = ((targetWidth - currentWidth) / 2);
	bgDivPhoto.style.position = "fixed";
	scaleImage();
//	bodyElements[0].style.background = "none";
}
function scaleImage() {
	currentWidth = currentWidth + ((targetWidth - currentWidth) / 5);
	currentHeight = currentHeight + ((targetHeight - currentHeight) / 5);
	currentTopPos = currentTopPos + ((targetTopPos - currentTopPos) / 5);
	currentLeftPos = currentLeftPos + ((targetLeftPos - currentLeftPos) / 5);
	bgDivPhoto.width = Math.round(currentWidth);
	bgDivPhoto.height = Math.round(currentHeight);
	bgDivPhoto.style.top = Math.round(currentTopPos) + "px";
	bgDivPhoto.style.left = Math.round(currentLeftPos) + "px";
	if (targetWidth != Math.round(currentWidth)) {
		window.setTimeout("scaleImage()", 50);
	}
	else return;
}
window.onresize = resizeImage;
