function resize_postimage() {
	
	theBody=document.getElementById("body");
	thePostImage = document.getElementById("post-image");
	
	maxWidthHeight=Math.min(theBody.clientHeight-75,theBody.clientWidth-685);
	
	thePostImageSrc=thePostImage.src; // src of the post-image
	thePostImageSrcExt=thePostImageSrc.substr(thePostImageSrc.length-3,3); // extension of the image file
	
	
	if (thePostImageSrcExt=='jpg') {
		// we don't scale jpg images since IE does a horrible job (and Firefox is not much better)
		
		// calculate maximum size (200,300,400,500 or 600)
		newWidthHeight = Math.max(Math.min(100*Math.floor(maxWidthHeight/100),600),200);
		
		// create new img src string 
		newPostImageSrc=thePostImageSrc.substr(0,thePostImageSrc.length-7) + newWidthHeight + '.jpg';
		
		// set new src, height & width
		thePostImage.style.height = parseInt(newWidthHeight) + "px";
		thePostImage.style.width = parseInt(newWidthHeight) + "px";
		thePostImage.src=newPostImageSrc;
		
	} else {
		// scale image, we don't mind if the GIF is a bit grainy
		newWidthHeight = 0.85*maxWidthHeight;
		thePostImage.style.height = parseInt(newWidthHeight) + "px";
		thePostImage.style.width = parseInt(newWidthHeight) + "px";
	}
}

function resize_divs() {
	theBody=document.getElementById("body");	
	thePostwrapper = document.getElementById("postwrapper");
	thePostImageWrapper = document.getElementById("post-image-wrapper");
		
	thePostwrapper.style.height = theBody.clientHeight-75;
	thePostwrapper.style.width = theBody.clientWidth + "px";
	
	thePostImageWrapper.style.height = theBody.clientHeight-75;
}

function ielayerfix_onresize() {
	if (navigator.appName == "Microsoft Internet Explorer") {
		resize_divs();
	}
	resize_postimage();
}

function ielayerfix_onload() {

	// Fix for IE not applying CSS bottom/right attributes.
	if (navigator.appName == "Microsoft Internet Explorer") {
		
		// change CSS of body back to what it was before applying IE-specific CSS
		// IE-specific CSS is fall back if javascript is not supported
		theBody=document.getElementById("body");
		thePostwrapper = document.getElementById("postwrapper");
		
		theBody.style.height = "100%";
		theBody.style.overflow = "hidden";
		
		thePostwrapper.style.overflow = "auto";
		
		resize_divs();
	}
	
	// resize the postimage
	resize_postimage();
	
	// unhide the postimage
	set_postimage_visibility("visible");
}

function set_postimage_visibility(v) {
	// hides postimage
	thePostImage = document.getElementById("post-image");
	thePostImage.style.visibility = v;
}

function emaillink(theName) {
	theEmailaddress=theName+'@columnistisch.nl';
	document.write('<a href="javascript:emailto(\'' + theName + '\');">' + theEmailaddress + '</a>');
}
function emailto(theName) {
	theEmailaddress=theName+'@columnistisch.nl';
	document.location='mailto:' + theEmailaddress;	
}

// hide postimage until it is resized
//set_postimage_visibility("hidden");

// attach resize function
//window.onresize = ielayerfix_onresize();
//window.onload= ielayerfix_onload();
