if ( ! ImgWidthReduceWidth ) var ImgWidthReduceWidth = 430;

var ImgWidthReduce = function () {
	return {

		size : function () {
			var w = 0;
			var h = 0;

			if ( ! window.innerWidth ) {
				if ( ! ( document.documentElement.clientWidth == 0 ) ) {
					w = document.documentElement.clientWidth;
					h = document.documentElement.clientHeight;
				}
				else {
					w = document.body.clientWidth;
					h = document.body.clientHeight;
				}
			}
			else {
				w = window.innerWidth;
				h = window.innerHeight;
			}

			return { width:w, height:h };
		},

		resize : function () {
			var pictures = document.getElementsByTagName("img");
			for ( var i in pictures ) {
				if ( pictures[i].className == "img_width_reduce" ) {
					pictures[i].style.width = ImgWidthReduce.size().width - ImgWidthReduceWidth + "px";
				}
				if ( pictures[i].className == "img_size_reduce" ) {
					pictures[i].style.width = ImgWidthReduce.size().width + "px";
					pictures[i].style.height = ImgWidthReduce.size().height + "px";
				}
			}
		},

		popup : function ( imgSrc, imgName ) {
			var imgPopup = window.open(
				"",
				"imgPopup",
				"status=0,statusbar=0,toolbar=0,location=0,menubar=0,directories=0,resizeable=0" +
					",width=640,height=480"
			);

			imgPopup.document.write(
				'<?xml version="1.0" encoding="utf-8"?>' +
				'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" ' +
					'"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">' +

				'<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">' +
				    '<head>' +
				        '<title>' + imgName + '</title>' +
				        '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />' +
				        '<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />' +
						'<script type="text/javascript" src="/site/scripts/img_width_reduce.js"></script>' +
				    '</head>' +
				    '<body style="margin: 0px">' +
						'<img src="' + imgSrc + '" width="640" class="img_size_reduce" ' +
							'alt="' + imgName + '" />' +
				    '</body>' +
				'</html>'
			);
		}

	};
}();

if ( document.addEventListener ) {
	document.addEventListener(
		"DOMContentLoaded", ImgWidthReduce.resize, false
	);
}
else if ( document.all && ! window.opera ) {
	document.write(
		'<script type="text/javascript" id="ImgWidthReduce.resize.loader" ' +
		'defer="defer" src="javascript:void(0)"><\/script>'
	);
	var contentLoader = document.getElementById("ImgWidthReduce.resize.loader");
	contentLoader.onreadystatechange = function () {
		if ( this.readyState == "complete" ) ImgWidthReduce.resize();
	}
}

window.onresize = function () {
	ImgWidthReduce.resize()
}
