
function openImageInNewWindow(imageUrl)
{
	var syncProxy = new GalleryAjaxServer();
	
	var result = syncProxy.getImageSize(imageUrl);

	if(result.status != "ok")
	{
		alert("Невозможно показать изображение");
		return false;
	}

	var imageWidth = result.width + 50;
	var imageHeight = result.height + 50;

	var availWidth = screen.availWidth - 100;
	var availHeight = screen.availHeight - 100;

	var width = (availWidth > imageWidth ? imageWidth : availWidth);
	var height = (availHeight > imageHeight ? imageHeight  : availHeight);

	var left = Math.round((screen.availWidth - width) / 2);
	var top = Math.round((screen.availHeight - height) / 2);

	var options = new Array(
		"location=no",
		"menubar=no",
		"status=no",
		"toolbar=no",
		"scrollbars=yes",
		"resizable=yes",
		"width=" + width,
		"height=" + height,
		"left=" + left,
		"top=" + top
	);

	var newWindow = window.open("", "_blank", options.join(","));

	newWindow.document.open();
	newWindow.document.write("<div align='center'>");
	newWindow.document.write("<img src='" + imageUrl + "' onclick='window.close();' style='cursor: pointer;'>");
	newWindow.document.write("</div>");
	newWindow.document.close();

	return newWindow;
}

