// Shows a given image in a new window with close button
// Based on a Script by Thomas Stich
// http://www.stichpunkt.de/beitrag/popup.html
// Extened by Gerald Schuberth
// use it if you like it
// 
// <a href="html-or.jpg" onclick="return popup(this,123,456)" title="..."
// or
// <a href="html-or.jpg" onclick="return popup(this)" title="..."


var pop = null;

function popdown() {
  if (pop && !pop.closed) pop.close();
}

function popup(obj,w,h) {
  var url = (obj.getAttribute) ? obj.getAttribute('href') : obj.href;
  if (!url) return true;
  w = (w) ? w += 50 : 150;  // 150px*150px is the default size
  h = (h) ? h += 100 : 150;
  var args = 'width='+w+',height='+h+',resizable=yes,status=no';
  popdown();
  pop = window.open('', '', args);
  pop.document.writeln('<?xml version="1.0" encoding="UTF-8" ?>');
  pop.document.writeln('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">');
  pop.document.writeln('	<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" ><head>');
  pop.document.writeln('	<meta http-equiv="content-type" content="text/html; charset=UTF-8" />');
  pop.document.writeln('	<title>'+url+'</title>');
  pop.document.writeln('<style type="text/css" media="screen" title="imageWindow style"><!--');
  pop.document.writeln('body {font-size: 1em;font-family: verdana, helvetica, arial, sans-serif;	margin: 0em;padding: 0em;background-color: black;	color: white;text-align:center;}');
  pop.document.writeln('img {border: none;margin: 5px;padding: 5px;}');
  pop.document.writeln('--></style></head><body>');
  pop.document.writeln('<p><img src="'+url+'" alt="'+url+'" /></p>');
  pop.document.writeln('<form action="" style="text-align:center;"><input type="button" value="close" onclick="self.close()"></form>');
  pop.document.writeln('</body></html>');
  pop.focus();
  return (pop) ? false : true;
}

window.onunload = popdown;
window.onfocus = popdown;

