/* PHOTO GALLERY

These functions are used by the photo gallery ASP script.

*/

/* ########## Shows picture in popup window. ########## */
function viewPhoto(photoURL, webURL) {

	// Declare script variables.
	var pageHTML;
	var page;
	
	// Defines page content for pop-up window.
	pageHTML = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">";
	pageHTML = pageHTML + "<html><head><title>Photo Gallery: Picture</title>";
	pageHTML = pageHTML + "<script src=\"gallery.js\" type=\"text/javascript\"></script>";
	pageHTML = pageHTML + "</head><body style=\"margin:0px\" onload=\"resizeWindow()\">";
	pageHTML = pageHTML + "<img name=\"galleryPhoto\" src=\"http://" + webURL + "/images/gallery/" + photoURL + "\" alt=\"\" border=\"\">";
	pageHTML = pageHTML + "</body></html>";
	
	// Opens new window and writes page code.
	page = window.open(photoURL, "", "toolbar=0, location=0, directories=0, menubar=no, scrollbars=no, resizable=yes, width=250, height=250");
	page.document.open();
	page.document.write(pageHTML);
	page.document.close();
}

/* ########## Resizes pop-up window after graphic has loaded. ########## */
function resizeWindow() {
	
	// Declare script variables.
	var objImage = document.galleryPhoto;
	var intCount = 0;
	var intImgHeight;
	var intImgWidth;
	
	// Wait until image has loaded before checking its size.
	while (objImage.complete == false) {
		wait(1000);
		intCount = intCount + 1;
		if (intCount > 10) {
			alert("Count= " + intCount);
			break;
		}
	}
	
	// Find the size of the image.
	intImgHeight = objImage.height;
	intImgWidth = objImage.width;
	
	// If image is too big, resize the image and then window.
	if (intImgHeight > intImgWidth) {
		if (intImgHeight > 420) {
			intImgHeight = 400;
			objImage.height = 400;
		}
	} else {
		if (intImgHeight > 600) {
			intImgHeight = 560;
			objImage.height = 560;
		}
	}
	
	// Reset image dimensions in case code has changed them.
	intImgHeight = objImage.height;
	intImgWidth = objImage.width;
	
	// Resize the container window.
	window.resizeTo(intImgWidth + 12, intImgHeight + 85) // 12 = width IE adds, 73 = height IE adds.
}

/* ########## Waits a specified amount of milliseconds. ########## */
function wait(intTime) {
	window.setTimeout(doNothing(), intTime);
}
function doNothing() {
	// Does nothing.
}

