var zoomStep = 1.25;

function openPopup (name, reqWidth, reqHeight, event)
{
	var new_window = window.open (
		name,
		'Image',
		'width=' + reqWidth + ',' +
		'height=' + reqHeight + ',' +
		'left=75,' +
		'top=65,' +
		'channelmode=no,' +
		'directories=yes,' +
		'fullscreen=no,' +
		'location=no,' +
		'menubar=no,' +
		'resizable=yes,' +
		'scrollbars=yes,' +
		'status=yes,' +
		'titlebar=yes,' +
		'toolbar=no',
		false
	);
	if ('focus' in new_window) {
		new_window.focus ();
	}
	if ('preventDefault' in event) {
		event.preventDefault ();
	} else if ('returnValue' in event) {
		event.returnValue = false;
	}
}

function zoomIn ()
{
	if (zoomCheckIncrease () == false) {
		return;
	}
	++currentZoom;
	updateWindowSize ();
}

function zoomOut ()
{
	--currentZoom;
	updateWindowSize ();
}

function zoomCheckIncrease ()
{
	var zoomFactor, newWidth, newHeight;

	if (limitZoom == false) {
		return (true);
	}
	zoomFactor = Math.pow (zoomStep, currentZoom + 1);
	return (
		(initialWidth * zoomFactor <= screen.availWidth) &&
		(initialHeight * zoomFactor <= screen.availHeight)
	);
}

function updateWindowSize ()
{
	var zoomFactor, newWidth, newHeight, domStyle, domObj;

	zoomFactor = Math.pow (zoomStep, currentZoom);
	newWidth = initialWidth * zoomFactor;
	newHeight = initialHeight * zoomFactor;
	domObj = document.getElementById ('main_image');
	domObj.style.width = newWidth + 'px';
	domObj.style.height = newHeight + 'px';
	if ((domObj = document.getElementById ('main_description')) !== null) {
		domObj.style.width = newWidth + 'px';
	}
	if (window.opener) {
		setTimeout (adjustPopupDimensions, 0);
	}
}

function adjustPopupDimensions ()
{
	var msie, width, height;

	msie = (navigator.appName == 'Microsoft Internet Explorer');
	width =
		document.getElementById ('main_image').offsetWidth +
		(msie ? 50 : 40);
	height =
		(
			(document.body.scrollHeight > document.body.offsetHeight) ?
			document.body.scrollHeight :
			document.body.offsetHeight
		) +
		(msie ? 115 : 75);
	if (width > screen.availWidth) {
		width = screen.availWidth;
	}
	if (height > screen.availHeight) {
		height = screen.availHeight;
	}
	window.resizeTo (width, height);
}
