function hide(myId) {
	if (document.getElementById && document.createElement) {
		document.getElementById('popupImg').src = '/images/shim.gif';
		myId.style.visibility = 'hidden';
	}
}

function show(imgLink) {
	if (document.getElementById && document.createElement) {
 					
		var imgSrc = imgLink.getAttribute('href');
		var imgLowSrc = imgSrc.replace(/big-/, "th-");
		theImg = document.getElementById('popupImg');
		theImg.setAttribute('src', imgLowSrc);
		theImg.setAttribute('src', imgSrc);

		/* parse image href for dimensions
		based on http://www.themaninblue.com/writing/perspective/2004/08/05/ */
		
		var paramString = imgSrc.replace(/.*\?(.*)/, "$1");
 		var paramTokens = paramString.split("&");
 		var paramList = new Array();

 		for (i = 0; i < paramTokens.length; i++) {
			var paramName = paramTokens[i].replace(/(.*)=.*/, "$1");
			var paramValue = paramTokens[i].replace(/.*=(.*)/, "$1");
			paramList[paramName] = paramValue;
		 }
 		theWidth = paramList["width"];
 		theHeight = paramList["height"];
 		
 		/* position popup */
 		
 		if (theWidth) {theImg.style.width = theWidth + 'px'}
 		if (theHeight) {theImg.style.height = theHeight + 'px'}
		
		viewportHeight=getInnerHeight();
		viewportWidth=getInnerWidth();
		downScroll = getVertScroll();
		rightScroll = getHorizScroll();
		
		if (document.getElementById('popup').offsetWidth) {
			popupWidth = document.getElementById('popup').offsetWidth;
			popupHeight = document.getElementById('popup').offsetHeight;
		} else {
			popupWidth = 714;
			popHeight = 505;
		}
		
		var shadow = 13;
		
		topPos = ((viewportHeight - popupHeight) / 2) + shadow + downScroll;
		leftPos = ((viewportWidth - popupWidth) / 2) + shadow + rightScroll;
		topPos = (topPos < (shadow+3))?(shadow+3):topPos;
		leftPos = (leftPos < (shadow+3))?(shadow+3):leftPos;
		document.getElementById('popup').style.top = topPos+"px";
		document.getElementById('popup').style.left = leftPos+"px";
		document.getElementById('popup').style.visibility = 'visible';
		return false
	} else {
		return true
	}
}

function getInnerHeight() {
	var y;
	if (self.innerHeight) // all except Explorer
	{
		y = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight)
		// Explorer 6 Strict Mode
	{
		y = document.documentElement.clientHeight;
	}
	else if (document.body) // other Explorers
	{
		y = document.body.clientHeight;
	}
	return y;
}

function getInnerWidth() {
	var x;
	if (self.innerHeight) // all except Explorer
	{
		x = self.innerWidth;
	}
	else if (document.documentElement && document.documentElement.clientHeight)
		// Explorer 6 Strict Mode
	{
		x = document.documentElement.clientWidth;
	}
	else if (document.body) // other Explorers
	{
		x = document.body.clientWidth;
	}
	return x;
}

function getVertScroll() {
	var y;
	if (self.pageYOffset) // all except Explorer
	{
		y = self.pageYOffset;
	}
	else if (document.documentElement && document.documentElement.scrollTop)
		// Explorer 6 Strict
	{
		y = document.documentElement.scrollTop;
	}
	else if (document.body) // all other Explorers
	{
		y = document.body.scrollTop;
	}
	return y;
}

function getHorizScroll() {
	var x;
	if (self.pageYOffset) // all except Explorer
	{
		x = self.pageXOffset;
	}
	else if (document.documentElement && document.documentElement.scrollTop)
		// Explorer 6 Strict
	{
		x = document.documentElement.scrollLeft;
	}
	else if (document.body) // all other Explorers
	{
		x = document.body.scrollLeft;
	}
	return x;
}

window.onload = function() {
	if (!document.getElementById || !document.createElement) return false;

	// create image popup nodes
	var popup = document.createElement('div');
	popup.setAttribute('id','popup');
	var para = document.createElement('p');
	var closetext = document.createTextNode('Close window');
	var linebreak = document.createElement('br');
	var photo = document.createElement('img');
	photo.setAttribute('id','popupImg');
	photo.setAttribute('alt','');
	photo.setAttribute('src','/images/shim.gif');

	// build empty popup
	para.appendChild(closetext);
	para.appendChild(linebreak);
	para.appendChild(photo);
	popup.appendChild(para);
	popup.onclick = function() {
		return hide(this);
	}
	
	// attach popup to body
	var content = document.getElementById('content');
	var container = content.parentNode;
	container.appendChild(popup);

	// attach event handlers to images
	var sidebar = document.getElementById('sidebar');
	
	var listitems = sidebar.getElementsByTagName('li');
	for (j=0;j<listitems.length;j++) {
		var lnks = listitems[j].getElementsByTagName('a');
		for (i=0;i<lnks.length;i++) {
			lnks[i].onclick = function() {
				return show(this);
			}
			lnks[i].onkeypress = function() {
				return show(this);
			}
		}
	}
}


function doClear(theText) {
if (theText.value == theText.defaultValue) {
theText.value = ""
}
}

