<!--
/*
	Name: 		CImgInWnd.js
	Ver: 		1.0a
	Author: 	Andrey Korolkov

	Описание:
		Данный класс вывода изображения в отдельном окне.
*/
/*
	Параметры:
		imgPath - 		путь к рисункам скрипта
		new_window - 	аложок, если true - то рисунки будут открываться в новом окне, false - в противном случае.
*/
function CImgInWnd (imgPath, new_window) {
// private: {
	var popupwin = null; // Указатель на окно
// }
// public: {
		/*
			Устанавливает куки.
			Параметры:
				imgSrc - 	путь к файлу изображения
				winTitle - 	заголовок окна
		*/
		this.Show = function (imgSrc, winTitle) {
			var winName = '';
			var imgWidth = 32;
			var imgHeight = 32;

			winWidth = (imgWidth) ? imgWidth + 20 : null;
			winHeight = (imgHeight) ? imgHeight + 20 : null;

			var dims = getDims(winWidth, winHeight);

			if (popupwin != null && new_window == false) {
				popupwin.close();
				popupwin = null;
			}

			popupwin = window.open('', winName, 'menubar=no,toolbar=no,resizable=no,status=no' + dims.scrollbarsStr + dims.widthStr + dims.heightStr + dims.posCode);
			popupwin.resizeTo(dims.width + 12, dims.height + 62)

			if (popupwin) {
				popupwin.document.open();
				popupwin.document.write('<html><head><title>' + winTitle + '</title></head><body bgcolor="white" style="margin: 10px 10px; padding: 0px;">')
				popupwin.document.write('<div style="width:100%;" align="center"><a href="javascript: void(0);" onclick="window.close();"><img id="id_img" src="' + imgPath + 'loading.gif" width="' + imgWidth + '" height="' + imgHeight + '" border="0" /></a></div>')
				popupwin.document.write('</body></html>')
				popupwin.document.close();
				popupwin.focus();
			}
			
			imgPreloader = new Image();
		
			// once image is preloaded, resize image container
			imgPreloader.onload = function() {
				if (popupwin) {
					imgWidth = imgPreloader.width;
					imgHeight = imgPreloader.height;
					winWidth = (imgWidth) ? imgWidth + 20 : null;
					winHeight = (imgHeight) ? imgHeight + 20 : null;

					popupwin.document.getElementById('id_img').src = imgSrc;
					popupwin.document.getElementById('id_img').width = imgWidth;
					popupwin.document.getElementById('id_img').height = imgHeight;
					popupwin.focus();

					dims = getDims(winWidth, winHeight);
					popupwin.moveTo(dims.posX, dims.posY);
					popupwin.resizeTo(dims.width + 12, dims.height + 62)
				}
		
				imgPreloader.onload = function () {};	//	clear onLoad, IE behaves irratically with animated gifs otherwise 
			}

			imgPreloader.src = imgSrc;

			return false;
		}
// }
// private: {
	getDims = function (winWidth, winHeight){
		var dims = new Object();

		dims.widthStr = '';
		dims.heightStr = '';
		dims.scrollbars = false;

		if (winWidth) {
			dims.width = winWidth;

			if (screen.width < dims.width + 50){
				dims.width = screen.width - 50;
				dims.scrollbars = true;
			}

			dims.widthStr = ',width=' + dims.width;
		}

		if (winHeight) {
			dims.height = winHeight;

			if (screen.height < dims.height + 100){
				dims.height = screen.height - 100;
				dims.scrollbars = true;
			}

			dims.heightStr = ',height=' + dims.height;
		}

		dims.scrollbarsStr = (dims.scrollbars)? ',scrollbars=yes' : ',scrollbars=no';
		dims.posX = Math.round((screen.width - dims.width) / 2);
		dims.posY = Math.round((screen.height - winHeight) / 2);
		dims.posCode = (document.all)? ',left=' + dims.posX + ',top=' + dims.posY : ',screenX=' + dims.posX + ',screenY=' + dims.posY;

		return dims;
	}
// }
}
//-->