function openPopup (name, reqWidth, reqHeight, event)
{
	var dimensions;

	dimensions = getPopupDimensions (reqWidth, reqHeight);
	window.open (
		name,
		'Image',
		'width=' + dimensions ['width'] + ',' +
		'height=' + dimensions ['height'] + ',' +
		'channelmode=no,' +
		'directories=yes,' +
		'fullscreen=no,' +
		'location=no,' +
		'menubar=no,' +
		'resizable=yes,' +
		'scrollbars=yes,' +
		'status=yes,' +
		'titlebar=yes,' +
		'toolbar=no',
		false
	);
	if ('preventDefault' in event) {
		event.preventDefault ();
	} else if ('returnValue' in event) {
		event.returnValue = false;
	}
}

function zoomIn ()
{
	++currentZoom;
	updateWindowSize ();
}

function zoomOut ()
{
	--currentZoom;
	updateWindowSize ();
}

function updateWindowSize ()
{
	var zoomFactor, newWidth, newHeight, domStyle, dimensions;

	if (currentZoom < 0) {
		zoomFactor = Math.pow (0.75, -currentZoom);
		newWidth = initialWidth * zoomFactor;
		newHeight = initialHeight * zoomFactor;
	} else if (currentZoom == 0) {
		newWidth = initialWidth;
		newHeight = initialHeight;
	} else {
		zoomFactor = Math.pow (1.25, currentZoom);
		newWidth = initialWidth * zoomFactor;
		newHeight = initialHeight * zoomFactor;
	}
	domStyle = document.getElementById ('main_image').style;
	domStyle.width = newWidth + 'px';
	domStyle.height = newHeight + 'px';
	if (window.opener) {
		dimensions = getPopupDimensions (newWidth, newHeight);
		window.resizeTo (dimensions ['width'], dimensions ['height']);
	}
}

function getPopupDimensions (imageWidth, imageHeight)
{
	var popupWidth, popupHeight;

	if ((popupWidth = imageWidth + 50) > screen.availWidth) {
		popupWidth = screen.availWidth;
	}
	if ((popupHeight = imageHeight + 200) > screen.availHeight) {
		popupHeight = screen.availHeight;
	}
	return ({width: popupWidth, height: popupHeight});
}

