var modalBG = document.getElementById("modalBackground");
var modalContainer = document.getElementById("modalContainer");
var modalContent = document.getElementById("modalContent");
var modalFlashId = "modalFlash";

function showImageModal(imagepath) {
	//show faded modal bg
	if (is_IE()) {
		modalBG.style.width = getViewportWidth() + "px";
	}
	modalBG.style.display = "block";
	modalBG.style.height = getPageHeightWithScroll() + "px";
	
	//insert modal content into hidden div
	if (imagepath.indexOf(".swf") == -1) {
		modalContent.innerHTML = "<img onclick='hideImageModal();' src='"+imagepath+"' />";
	} else {
		modalContent.innerHTML = '<div id="'+modalFlashId+'"><div class="getFlashMsg"><p> <strong>Flash Player Recommended</strong></p><p>To view this page as it was intended, Flash Player 8 or higher is required.</p><p>To install or update Flash Player, click here:<br /><br /><a href="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" target="_blank"><img alt="Get Flash Player" src="/flash/media/images/get_flash_player.gif" border="0" /></a></p></div></div>';
		swfobject.embedSWF(imagepath, modalFlashId, "430", "302", "8","expressInstall.swf");
	}
	
	//show actual modal
	if (is_IE() == "6") {
		scrollTo(0,0);
		modalContainer.style.position = "absolute";	
	}
	updateModalContainerPosition();
	modalContainer.style.display = "block";
}

function updateModalContainerPosition() {
	modalContainer.style.top = (getViewportHeight() - 644)/2 + "px";
	modalContainer.style.left = (getViewportWidth() - 726)/2 + "px";
}

function hideImageModal() {
	modalBG.style.display = "none";
	modalContainer.style.display = "none";
}

window.onresize = updateModalContainerPosition;

function is_IE() {
	var ua = navigator.userAgent.toLowerCase();
	var ieStringPos = ua.indexOf("msie ");
	if (ieStringPos != -1) {
		return ua.charAt(ieStringPos+5);
	} else {
		return false;
	}
}
function getPageHeightWithScroll(){
	if (window.innerHeight && window.scrollMaxY) {// Firefox
		yWithScroll = window.innerHeight + window.scrollMaxY;
		xWithScroll = window.innerWidth + window.scrollMaxX;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		yWithScroll = document.body.scrollHeight;
		xWithScroll = document.body.scrollWidth;
	} else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari
		yWithScroll = document.body.offsetHeight;
		xWithScroll = document.body.offsetWidth;
  	}
	return yWithScroll;
}
function getViewportWidth() { //doesn't work correctly in FF3 and probably otrher standard browsers
	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 myWidth;
}
function getViewportHeight() {
	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 myHeight;
}
