/* This script was original in Templates\NewsDetail.aspx until 3 Jan 2007 */
/* It was moved to its own script file because captions have been added to all templates */

// This function detects the size of the image and resizes the caption accordingly.
function amendCaptionSize(){
	var imageWidth = 0;
	try{
		// "children works" with IE...  "childNodes" is the W3C/FF way...
		if(document.getElementById("phArticleImg").children)
			imageWidth = document.getElementById("phArticleImg").children[0].offsetWidth;
		else{
			// FF will treat any spaces preceding the image as the first childnode!
			imageWidth = document.getElementById("phArticleImg").childNodes[0].offsetWidth;
			if(imageWidth == undefined) imageWidth = document.getElementById("phArticleImg").childNodes[1].offsetWidth;
		}

		if(imageWidth > 0 && imageWidth < 500){
			document.getElementById("CaptionDiv").style.width = imageWidth + "px"
			document.getElementById("ImgDiv").style.width = imageWidth + "px"
		}
	}catch(err) { /*alert(err)*/ }
}

if(window.addEventListener)
	window.addEventListener("load", amendCaptionSize, false); // any standard-compliant browser...
else if(document.all && document.getElementById)
	window.onload = amendCaptionSize;  // Only do this for IE5+