function initPopUps() {
	if (document.getElementsByTagName) {
		var n, hyperlink;
		var linkArray = document.getElementsByTagName("a");

		for (n = 0; n < linkArray.length; n++) {
			hyperlink = linkArray[n];

			if (hyperlink.className == "small-image") {
				hyperlink.onclick = function () {popUp(this.getAttribute("href")); return false;};
			}
		}
	}
}

function openUrl(sUrl, nWidth, nHeight) {
	window.open(sUrl, "_blank", "width=" + nWidth + ",height=" + nHeight + ",status=no,resizable=yes,scrollbars=yes");
}

function popUp(sURL) {
	var sFeatures, sHTML;
	oImage = new Image();
	
	oImage.src = sURL;
	
	if (oImage.complete) {
		resizePopUp();
	} else {
		oImage.onload = resizePopUp;
	}
}

function resizePopUp() {
	var nWidth, nHeight;
	
	nWidth = (parseInt(oImage.width) + 50 > screen.width) ? screen.width - 50 : parseInt(oImage.width) + 25;
	nHeight = (parseInt(oImage.height) + 200 > screen.height) ? screen.height - 200 : parseInt(oImage.height) + 110;
	
	sFeatures = "width=" + nWidth + ", height=" + nHeight + ", status=no, scrollbars=yes";
	
	sHTML = "<html><head><title>Image Viewer</title>";
	sHTML += "<meta http-equiv='imagetoolbar' content='no'>";
	sHTML += "<script type='text/javascript' src='/scripts/scripts.js'></script>";
	sHTML += "</head><body style='margin:5px 0 0;padding:0;text-align:center;font:12px sans-serif'>";
	sHTML += "<img src='" + oImage.src + "' alt='' onclick='window.close();'>";
	sHTML += "<p><a href='javascript:window.close();'>Close Window</a></p>";
	sHTML += "</body></html>";

	oWin = window.open("", "", sFeatures);
	oWin.document.open();
	oWin.document.write(sHTML);
	oWin.document.close();
}

function adjustExternalLinks() {
	if (document.getElementsByTagName) {
		var n, hyperlink;
		var linkArray = document.getElementsByTagName("a");

		for (n = 0; n < linkArray.length; n++) {
			hyperlink = linkArray[n];

			if (hyperlink.className == "external-link") {
				hyperlink.onclick = function () {window.open(this.href, "_blank", "width=800, height=600, scrollbars=yes, resizable=yes, toolbar=yes, status=yes"); return false;};
			}
		}
	}
}

if (window.addEventListener) {
	window.addEventListener("load", initPopUps, false);
	window.addEventListener("load", adjustExternalLinks, false);
} else if (window.attachEvent) {
	window.attachEvent("onload", initPopUps);
	window.attachEvent("onload", adjustExternalLinks);
}
