var newwindow;

function popup_image(imagesrc,title,overlaysrc)
{
var pwidth, pheight;

  if (!newwindow || newwindow.closed)
  {
    pwidth=150;
    pheight=150;
    newwindow=window.open('','','status=0,width='+pwidth+',height='+pheight+',resizable=1,scrollbars=1');
  }
  
  newwindow.document.clear();
  newwindow.document.writeln('<html><head><title>'+title+'</title>');
  newwindow.document.writeln('<script language="JavaScript">');
  newwindow.document.writeln('var ie5, nn4,nn6;');
  newwindow.document.writeln('var buttonHeight = 60;');
  newwindow.document.writeln('var hScreenPadding = 20;');
  newwindow.document.writeln('var vScreenPadding = 10;');
  newwindow.document.writeln('var scrollBarSize = 30;');
  newwindow.document.writeln('var addressBarSize = 25;');
  newwindow.document.writeln('var screenHeight = screen.height - vScreenPadding * 2;');
  newwindow.document.writeln('var screenWidth = screen.width - hScreenPadding * 2;');
  newwindow.document.writeln('ie5=nn4=nn6=false;');
  newwindow.document.writeln('if (document.all){');
  newwindow.document.writeln('ie5=true;');
  newwindow.document.writeln('} else if (document.getElementById) {');
  newwindow.document.writeln('nn6=true;');
  newwindow.document.writeln('} else if (document.layers) {');
  newwindow.document.writeln('nn4=true;}');
  newwindow.document.writeln('function autoResize() {');
  newwindow.document.writeln('var imageHeight, imageWidth, w ,h;');
  newwindow.document.writeln('imageHeight = document.images[0].height;');
  newwindow.document.writeln('imageWidth = document.images[0].width;');
  newwindow.document.writeln('h = Math.min(imageHeight + buttonHeight + scrollBarSize + addressBarSize, screenHeight);');
  newwindow.document.writeln('w = Math.min(imageWidth + scrollBarSize, screenWidth);');
  newwindow.document.writeln('if (ie5) {');
  newwindow.document.writeln('self.resizeTo(w, h);');
  newwindow.document.writeln('} else {');
  newwindow.document.writeln('top.window.resizeTo(w, h);}');
  newwindow.document.writeln('self.focus(); }');
  newwindow.document.writeln('function over() {document.getElementById("overlay").style.visibility="visible";}');
  newwindow.document.writeln('function out()  {document.getElementById("overlay").style.visibility="hidden";}');
  newwindow.document.writeln('</script>');
  newwindow.document.writeln('</head>');
  newwindow.document.writeln('<body text="#FFFFFF" bgcolor="#000000" topmargin="0" leftmargin="0" marginwidth="0" onload="autoResize();">');
  newwindow.document.writeln('<center>');
  if (overlaysrc.length == 0)
  {
  	newwindow.document.writeln('<img src="http://www.wilmslowastro.com/gallery/l100/'+imagesrc+'" border="0" /><br />');
  }
  else
  {
  	newwindow.document.writeln('<div style="position:relative">');
  	newwindow.document.writeln('<img src="http://www.wilmslowastro.com/gallery/l100/'+imagesrc+'" border="0" onmouseover="over()" onmouseout="out()" /><br />');
  	newwindow.document.writeln('<img id="overlay" src="http://www.wilmslowastro.com/gallery/l100/'+overlaysrc+'" border="0" style="position:absolute;top:0px;left:0px;visibility:hidden"  onmouseover="over()" onmouseout="out()" />');
  	newwindow.document.writeln('</div>');
  }
  newwindow.document.writeln('<input type="button" value="Close Window" onclick="window.close();" name="close"></center></body>');
  newwindow.document.close();
  newwindow.focus();
}

// Routines to tidy up popup windows when page is left
// Call with an onUnload="tidy5()" in body tag
function tidy5()
{
  if (newwindow && !newwindow.closed) 
  { 
    newwindow.close();
  }
}

