/*
This work is licensed under the Creative Commons Attribution License.
To view a copy of this license, visit http://creativecommons.org/licenses/by/2.0/
2004, 2005 Björn Graf, bjoern.graf@gmx.net, http://b-cage.net/
*/

function picPop(url, text) {
	// Required for some IE versions only
	if(window.event) window.event.cancelBubble = true;

	var x = y = 0;
	if(window.screenLeft){
		if(screen.availWidth < window.screenLeft || window.screenLeft < 0 ||
			screen.availHeight < window.screenTop || window.screenTop < 0) {
			x = window.screenLeft;
			y = window.screenTop;
			var doMove = true;
		}
	} else if(window.screenX) {
		if(screen.availWidth < window.screenX || window.screenX < 0 ||
			screen.availHeight < window.screenY || window.screenY < 0) {
			x = window.screenX;
			y = window.screenY;
		}
	}

	var win = window.open('', 'picPopup', 'left=' + x + ',top=' + y + ',width=200,height=200,location=0,menubar=0,statusbar=0');
	win.document.write('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"\n' +
		'	"http://www.w3.org/TR/html4/strict.dtd">\n' +
		'<html><head><title>Full view</title><style type="text/css">\n' +
		'html,body{margin:0;padding:0;overflow:hidden;width:100%;height:100%;}\n' +
		'img{margin:0;padding:0;}\n' +
		'p{margin:0;padding:0.5em;text-align:center;}\n' +
		'</style><script type="text/javascript">\n' +
		'onload = function() {\n' +
		'	var b=document.body;\n' +
		'	var d=document.getElementById("d");\n' + 
		'	var i=document.getElementById("i");' +
		'	if(!d.offsetWidth) { b.style.overflow = "visible"; b.style.overflow = "hidden"; }\n' +
		'	var w = Math.max(d.offsetWidth, i.offsetWidth);\n'+
		'	window.resizeBy(w - b.offsetWidth, d.offsetHeight - b.offsetHeight);\n');
		if(x == 0 && y == 0) win.document.write('	window.moveTo((screen.availWidth - b.offsetWidth) / 2, (screen.availHeight - b.offsetHeight) / 2);\n');
		else if(doMove) win.document.write('	window.moveTo(' + x + ', ' + y + ');\n');
		win.document.write('	window.focus();\n' +
		'}\n' +
		'</scr' + 'ipt></head><body><div id="d"><img id="i" src="' + url + '">\n');
	if(text) win.document.write('<p>' + text + '</p>');
	win.document.write('</div></body></html>');
	win.document.close();
	return !win;
}

