ResizePop.DegradeTarget = "_self";
ResizePop.ClickImageToClose = true;
ResizePop.CloseOpenWindows = true;
ResizePop.Messages = {
	loading: "Loading...",
	loadingSub: "please wait...",
	errorLoading: "Image not found.",
	errorLoadingSub: "Unloaded",
	errorLoadingClose: "Close",
	noResize: "Loaded image.",
	noResizeSub: "Your browser is not able to resize the pop-up.",
	noResizeView: "Show image",
	imageCloseTip: "Click to close"
};
ResizePop.Version = 2.7;
ResizePop.imgWin = null;
ResizePop.ieSp2 = (navigator.appName.toLowerCase().indexOf("internet explorer") > -1
	&& navigator.appMinorVersion.toLowerCase().indexOf("sp2") > -1);
function ResizePop(img, imgTitle) {
	function degrade() {
		switch(ResizePop.DegradeTarget) {
			case "_blank" : open(img); break;
			case "_self" : location = img; break;
			case "_top" : top.location = img; break;
			case "_parent" : parent.location = img; break;
			default : open(img, ResizePop.DegradeTarget);
		}
		return false;
	}
	if(!document.images || !document.getElementById) { return degrade(); }
	if(ResizePop.CloseOpenWindows && ResizePop.imgWin) {
		if(ResizePop.imgWin.close) { ResizePop.imgWin.close(); }
		ResizePop.imgWin = null;
	}
	var width = 150, height = 100;
	if(ResizePop.ieSp2) { height += 20; }
	var left = (screen.availWidth - width)/2, top = (screen.availHeight - height)/ 2;
	var imgWin = window.open("about:blank", "", "width=" + width + ",height=" + height + ",left=" + left + ",top=" + top);
	if(!imgWin) { return degrade(); }
	imgTitle = imgTitle || "Image (" + img + ")";
	var html = '<html><head><title>PopUp</title>'
		+ '\n<script type="text/javascript">\nvar _e = null;'
		+ '\nvar ip = window.opener.ResizePop;'
		+ '\nvar _pageLoaded = false;'
		+ '\nvar _title = "' + imgTitle + '"'
		+ '\nonload = function(e) { _pageLoaded = true; }'
		+ '\nfunction imgLoad(e) { ip.ImageLoaded(e, window); }'
		+ '\nfunction imgError(e) { ip.ErrorLoading(e, window); }'
		+ '\nimgShow = ip.ImageShow;'
		+ '\nimgManualPopup = ip.ImageLoadedManualPopup;'
		+ '\n</script>'
		+ '\n<style type="text/css">'
		+ '\nhtml, body { font : 12px Arial; margin : 0; overflow : hidden; } h1 { font-size : 1.5em; }'
		+ '\n h2 { font-size : 1.2em; } a { color : blue; } img { visibility: hidden; border-color : black; }'
		+ '\n .message { position : absolute; left : 0px; top : 0px; width : 150px; height : 100px; background : white; text-align : center; }'
		+ '\n .message .main-message { font-weight : bold; display : block; }'
		+ '\n .message .secondary-message { color : #999; font-size : 11px; }'
		+ '\n .main-message.loading { margin-top : 35px; } .main-message.loaded { margin-top : 33px; } .main-message.error { margin-top : 25px; }'
		+ '\n #loading { z-index : 50; } #resize { z-index : 30; } #error { z-index : 40; }'
		+ '\n #image { position : absolute; left : 0px; top : 0px; width : 100%; height : 100%; z-index : 20; padding : 0px; background : white; }'
		+ '\n</style>'
		+ '\n</head>\n<body>'
		+ '\n<div id="loading" class="message"><span class="main-message loading">'
		+ ResizePop.Messages.loading
		+ '</span> <span class="secondary-message">'
		+ ResizePop.Messages.loadingSub
		+ '</span></div>'
		+ '\n<div id="error" class="message"><span class="main-message error">'
		+ ResizePop.Messages.errorLoading
		+ '</span> <span class="secondary-message">'
		+ ResizePop.Messages.errorLoadingSub
		+ '<br><a href="javascript:window.close()">'
		+ ResizePop.Messages.errorLoadingClose
		+ '</a></span></div>'
		+ '\n<div id="resize" class="message"><span class="main-message error">'
		+ ResizePop.Messages.noResize
		+ '</span> <span class="secondary-message">'
		+ ResizePop.Messages.noResizeSub
		+ '<br><a href="javascript:imgManualPopup(_e, window)">'
		+ ResizePop.Messages.noResizeView
		+ '</a></span></div>'
		+ '\n<div id="image" align="center">';
	if(ResizePop.ClickImageToClose) {
			html += '\n<a href="javascript:window.close()" title="'
			+ ResizePop.Messages.imageCloseTip
			+ '">';
	}
	html += '\n<img src="' + img + '" id="theImg" border="0" onload="imgLoad(this)" onerror="imgError(this)">';
	if(ResizePop.ClickImageToClose) { html += '</a>'; }
	html += '\n</div>'
		+ '\n</body></html>';
	imgWin.document.open();
	imgWin.document.write(html);
	imgWin.document.close();
	ResizePop.imgWin = imgWin;
	return false;
}
ResizePop.ImageLoaded = function(e, win) {
	if(!e || !win) { return; }
	e.onload = null;
	e.onerror = null;
	if(win._pageLoaded) {
		function show() {
			win.imgShow(e, win);
		}
		win.setTimeout(show, 100);
	} else {
		function noShow() {
			win.imgLoad(e, win);
		}
		win.setTimeout(noShow, 100);
	}
}
ResizePop.ImageShow = function(e, win) {
	if(!e || !win) { return; }
	e.onload = null; e.onerror = null;
	var doc = win.document;
	var width = e.width + 30,
		height = e.height + 55;
	if(ResizePop.ieSp2 || (win.statusbar && win.statusbar.visible)) { height += 20; }
	var tooLarge = false;
	if(width > screen.availWidth) {
		width = screen.availWidth - 20;
		tooLarge = true;
	}
	if(height > screen.availHeight) {
		height = screen.availHeight - 20;
		tooLarge = true;
	}
	if(tooLarge) {
		doc.getElementById("image").style.overflow = "auto";
	}
	var tooSmall = false;
	if(e.width < doc.body.clientWidth && e.height < doc.body.clientHeight) {
		tooSmall = true;
	}
	var left = (screen.availWidth - width)/2, top = (screen.availHeight - height)/ 2;
	win.moveTo(left, top);
	win.resizeTo(width, height);
	var docElm = doc.documentElement || {};
	var winWidth = docElm.clientWidth||doc.body.clientWidth||win.innerWidth,
		winHeight = docElm.clientHeight||doc.body.clientHeight||win.innnerHeight;
	if( (tooLarge && (winWidth < 200 || winHeight < 200) )
		|| !tooLarge && !tooSmall && (e.width > 150 && winWidth <= 150 || e.height > 100 && winHeight <= 100) ) {
		win._e = {
			src : e.src,
			width : e.width,
			height : e.height,
			tooLarge : tooLarge
		}
		doc.getElementById("loading").style.display = "none";
		doc.getElementById("error").style.display = "none";
		doc.getElementById("image").style.display = "none";
		doc.title = "Image Loaded";
	} else {
		doc.getElementById("loading").style.display = "none";
		doc.getElementById("error").style.display = "none";
		doc.getElementById("resize").style.display = "none";
		doc.getElementById("theImg").style.visibility = "visible";
		doc.title = win._title;
	}
}
ResizePop.ErrorLoading = function(e, win) {
	if(!e || !win) { return; }
	var doc = win.document;
	e.onload = null; e.onerror = null;
	doc.getElementById("loading").style.display = "none";
	doc.getElementById("resize").style.display = "none";
	doc.getElementById("image").style.display = "none";
	doc.title = "Image not found";
}
ResizePop.ImageLoadedManualPopup = function(e, win) {
	if(!e || !win) { return; }
	var width = e.width + 20, height = e.height + 20;
	if(width > screen.availWidth) { width = screen.availWidth - 20; }
	if(height > screen.availHeight) { height = screen.availHeight - 100; }
	var left = (screen.availWidth - width)/2, top = (screen.availHeight - height)/ 2;
	win.open(e.src, "ManualImageViewer", "width=" + width + ",height=" + height + ",left=" + left + ",top=" + top + (e.tooLarge ? ",scrollbars" : ""));
	win.close();
}
ResizePop.AutoApply = function(container) {
	if(!container) { container = document; }
	var a = container.getElementsByTagName("A");
	for(var i = 0; i < a.length; i++) {
		if( a[i].href.match(/\.(gif|jpg|jpeg|png|bmp)$/i) ) {
			applyPopup(a[i]);
		}
	}
	function applyPopup(link) {
		var n, imgs = 0, whitespace = 0, alt = null;
		for(var i = 0; n = link.childNodes[i]; i++) {
			if(n.tagName == "IMG") {
				imgs++;
				alt = n.alt;
			} else if(n.nodeValue) {
				var val = n.nodeValue;
				if(val.replace(/\s+/g, "") == "") { whitespace++; }
			}
		}
		n = null;
		if(!alt) { alt = link.title; }
		link.onclick = function(e) { return ResizePop(this.href, alt); }
	}
}