/*
 * PopupImage.js
 * 
 * Produces an image in a popup window
 *
 * Not W3C compliant
 */

var win;
var d;
var i;
var action;

/*
 * popupImage() - opens an image in a new window on the center of the screen
 */
function popupImage(src) {
	var specs = "directories=no,location=no,menubar=no,resizable=yes,"
			+ "scrollbars=no,status=no,titlebar=no,toolbar=no"
	win = window.open("", "popWin", specs);
	
	d = win.document;
	
	d.open("text/html");
	d.writeln('<?xml version="1.0" encoding="utf-8"?>');
	d.writeln('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"');
	d.writeln('        "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">');
	d.writeln('<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">');
	d.writeln('<head>');
	d.writeln('	<meta http-equiv="content-type" content="text/html;' 
			+ 'charset=utf-8" />');
	d.writeln('	<title>' + document.title + '</title>');
	d.writeln('</head>');
	d.writeln('<body style="margin: 0px; padding: 0px">');
	d.writeln('<img id="image" src="' + src + '" style="margin: 0px" />');
	d.writeln('</body>');
	d.writeln('</html>');
	d.close();
	
	i = d.images[0];

	action = window.setTimeout("resizeWin()", 50);
}

function resizeWin() {	
	var w = i.width;
	var h = i.height;
	if (i.complete) {
		window.clearTimeout(action);
	} else {
		action = window.setTimeout("resizeWin()", 50);
		return;
	}
	
	win.resizeTo(w, h + 10);
	
	win.moveTo((screen.width / 2) - (w / 2), (screen.height / 2) - (h / 2));
}