// JimWells.js
// returns the width of the window
function getWidth(){
	var myWidth=0;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
	} else if( document.documentElement && document.documentElement.clientWidth ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
	} else if( document.body && document.body.clientWidth ) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
	}
	return parseInt(myWidth);
}

// returns the height of the window
function getHeight(){
	var myHeight=0;
	if( typeof( window.innerHeight ) == 'number' ) {
		//Non-IE
		myHeight = window.innerHeight;
	} else if( document.documentElement && document.documentElement.clientHeight ) {
		//IE 6+ in 'standards compliant mode'
		myHeight = document.documentElement.clientHeight;
	} else if( document.body && document.body.clientHeight ) {
		//IE 4 compatible
		myHeight = document.body.clientHeight;
	}
	return parseInt(myHeight);
}

// given the height and width of an image, figures out the largest width that will fit both dimensions of the browser window.
function setWidth(originalWidth,originalHeight){
	var windowWidth=getWidth();
	var windowHeight=getHeight();
	var transformedWidth=(originalWidth*(windowHeight-10))/originalHeight;
	if( transformedWidth>(windowWidth-10) ){
		// Fit the image to the window width
		transformedWidth=windowWidth-10;
	}
	return parseInt(transformedWidth);
}

// display an image in a fixed div.
function displayImage(image,width,height){
	var newWidth=setWidth(width,height);
	var newHeight=parseInt((height*newWidth)/width);
	// put the div in the middle of the screen
	var divTop=parseInt((getHeight()-(newHeight+10))/2);
	var divLeft=parseInt((getWidth()-(newWidth+10))/2);
	var objDiv=document.getElementById("imageWindow");
	objDiv.innerHTML="";
	objDiv.style.top=divTop+"px";
	objDiv.style.left=divLeft+"px";
	objDiv.height=newHeight;
	objDiv.width=newWidth;
	var objImage=document.createElement("img");
	objImage.src="images/image.php?image="+escape(image)+"&width="+parseInt(newWidth);
	objImage.height=newHeight;
	objImage.width=newWidth;
	objImage.alt="Click to close";
	objImage.title="Click to close";
	objImage.onclick=function(){document.getElementById('imageWindow').style.display='none';};
	objDiv.appendChild(objImage);
	objDiv.style.display="inline";
	return false;
}
