var img;
var images = new Array();
var lastSpan;

function appendImage(id) {
	images[id] = new Image();
	images[id].src = "images/"+id+"_l.jpg";
}

function showImg(id) {
	var divPop = document.getElementById("imgPop");
	var spanLink = document.getElementById("largerLink_"+id);
	if (lastSpan != null && lastSpan != spanLink) {
		lastSpan.innerHTML = "Larger Image";
	}
	if (spanLink.innerHTML == "Larger Image") {
		lastSpan = spanLink;
		/* Code below grabbed from https://lists.latech.edu/pipermail/javascript/2003-November/006674.html */
		var isIE = (navigator.appName.toLowerCase() == "microsoft internet explorer")
		var isNN = (navigator.appName.toLowerCase() == "netscape")
		//var objItem = document.getElementById("larger")
		var objItem = spanLink;
		var objParent = null
		var intX = 0
		var intY = 0
		do
			{ // Walk up our document tree until we find the body
			// and add the distance from the parent to our counter.
			intX += objItem.offsetLeft
			intY += objItem.offsetTop
			objParent = objItem.offsetParent.tagName
			objItem = objItem.offsetParent
			} while(objParent != 'BODY')
		
		
		var myScrollX
		var myScrollY
		(isIE) ? myScrollX = document.body.scrollLeft: myScrollX = window.pageXOffset;
		(isIE) ? myScrollY = document.body.scrollTop: myScrollY = window.pageYOffset;
		
		var intImgLeft = intX - myScrollX
		var intImgTop = intY - myScrollY
		/* OK, got the position of the link, now to stop using other people's code and use my own!*/
		
		divPop.style.display = "";
		divPop.style.zindex = 10;
		//divPop.style.background = "#FFF";
		//divPop.style.border = "1px solid #000";
		divPop.style.width = images[id].width;
		divPop.style.height = images[id].height;
		divPop.style.top = intY - images[id].height;
		divPop.style.left = intX - (images[id].width / 2);
		divPop.style.textAlign = "center";
		divPop.innerHTML = "<img src='images/"+id+"_l.jpg' align='absbottom'>";
		spanLink.innerHTML = "Close Image";
	} else { // spanLink.innerHTML == "Close Image"
		divPop.style.display = "none";
		spanLink.innerHTML = "Larger Image";
	}
}


function changeSize() {
	var t = win.document.title;
	var strHTML = '<html><head><title>'+t+'</title></head><body style="margin:0px;"><img src="'+
		img.src+'" height="'+img.height+'" width="'+img.width+'"></body></html>';
	var w = img.width;
	var h = img.height;
	if (parseInt(navigator.appVersion)>3) {
		if (navigator.appName=="Netscape") {
			while (!img.complete) {
				setTimeout("null",10);
			}
			win.innerWidth = img.width;
			win.innerHeight = img.height+50;
			w = win.outerWidth;
			h = win.outerHeight;
			win.document.write(strHTML);
			win.document.close(); // close the writing stream or else the page will never complete loading.
		} else if (navigator.appName.indexOf("Microsoft")!=-1) {
			win.document.write(strHTML);
			win.document.close(); // close the writing stream or else the page will never complete loading.
			alert("document.body.clientHeight: "+win.document.body.clientHeight+"\n"
				+"document.documentElement.clientHeight: "+win.document.body.scrollHeight);
			h += win.document.body.scrollHeight - win.document.body.clientHeight;
			w += win.document.body.scrollWidth - win.document.body.clientWidth;
			win.resizeTo(w, h);
		}
		x = (screen.width - w) / 2;
		y = (screen.height - h) / 2;
		win.moveTo(x,y);
	}
}