function WinImage(imageName,imageWidth,imageHeight,alt,bgcolor,hugMargin) {
// based on script by E Michael Brandt of ValleyWebDesigns.com

   if (bgcolor == "") { bgcolor="#000000"; }
   var adj = 10;
   var w = screen.width;
   var h = screen.height;
   var byFactor = 1;

   if (w < 740) { var lift = 0.90; }
   if (w >= 740 & w < 835) { var lift = 0.91; }
   if ( w >= 835) { var lift = 0.93; }
   if (imageWidth > w) {
     byFactor = w / imageWidth;
     imageWidth = w;
     imageHeight = imageHeight * byFactor;
   }
   if (imageHeight > h - adj) {
     byFactor = h / imageHeight;
     imageWidth = (imageWidth * byFactor);
     imageHeight = h;
   }

   var scrWidth = w - adj;
   var scrHeight = (h * lift) - adj;

   if (imageHeight > scrHeight) {
     imageHeight = imageHeight * lift;
     imageWidth = imageWidth * lift;
   }

   var posLeft = 0;
   var posTop = 0;

   if (hugMargin == "") { hugMargin = 0; }
   var scrHeightTemp = imageHeight - 0 + 2 * hugMargin;
   if (scrHeightTemp < scrHeight) { scrHeight = scrHeightTemp; }
   var scrWidthTemp = imageWidth - 0 + 2 * hugMargin;
   if (scrWidthTemp < scrWidth) { scrWidth = scrWidthTemp; }

   if (scrHeight < 100) { scrHeight = 100; }
   if (scrWidth < 100) { scrWidth = 100; }

   posTop = (h - (scrHeight / lift) - adj) / 2;
   posLeft = (w - (scrWidth) - adj) / 2;

   if (imageHeight > (h * lift) - adj || imageWidth > w - adj) {
      imageHeight = imageHeight - adj;
      imageWidth = imageWidth - adj;
   }
   posTop = parseInt(posTop);
   posLeft = parseInt(posLeft);
   scrWidth = parseInt(scrWidth);
   scrHeight = parseInt(scrHeight);

   newWindow = window.open("","newWindow","width="+scrWidth+",height="+scrHeight+",left="+posLeft+",top="+posTop);
   newWindow.document.open();
   newWindow.document.write('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">');
   newWindow.document.write('<HTML><HEAD><TITLE>'+alt+'</TITLE></HEAD>');
   newWindow.document.write('<BODY LEFTMARGIN="0" TOPMARGIN="0" MARGINHEIGHT="0" MARGINWIDTH="0" BGCOLOR='+bgcolor+' onBlur="self.close()" onClick="self.close()">');
   newWindow.document.write('<TABLE WIDTH='+imageWidth+' BORDER="0" CELLSPACING="0" CELLPADDING="0" ALIGN="CENTER" HEIGHT='+scrHeight+'>');
   newWindow.document.write('<TR><TD><IMG SRC="'+imageName+'" WIDTH='+imageWidth+' HEIGHT='+imageHeight+' ALT="Kliknutím zavøete okno">');
   newWindow.document.write('</TD></TR></TABLE></BODY></HTML>');
   newWindow.document.close();
   newWindow.focus();
}


