var winWidth=0;
var winHeight=0;
var imgWidth=1024;
var imgHeight=768;
var newWidth=0;
var newHeight=0;

function imgResize() {
	var bgimage=document.getElementById('bgimage');
	
	// establish browser width and height
	if(window.innerWidth) {
		winWidth=window.innerWidth;
		winHeight=window.innerHeight;
	
	// do it for IE	
	} else {
		winWidth=document.body.offsetWidth;
		winHeight=document.body.offsetHeight;
	}
	
	// calculate image width and height while maintaining aspect ratio
	if(winHeight>imgHeight||winHeight<imgHeight) {
		newHeight=winHeight;
		newWidth=winHeight*(imgWidth/imgHeight);
	}
	
	if(newWidth<winWidth) {
		newWidth=winWidth;
		newHeight=newWidth*(imgHeight/imgWidth);
	}
	
	// do the resize
	bgimage.style.width = newWidth + "px";
	bgimage.style.height = newHeight + "px";
	bgimage.style.display = "block";
}