var windowImage = null;
var nextImage=null;
var oldImage=null;
var maxWidth = 760;
var maxHeight = 600;

function showImage( imageName ) {
  // preload the image
	if (nextImage != null) oldImage = nextImage;
  nextImage = new Image();
  nextImage.src = imageName;

	// already loaded?
	if (oldImage != null && oldImage.src == nextImage.src) {
		imageLoaded(); 
	}
	else {
	  nextImage.onload = imageLoaded;
	}
}

function imageLoaded() {
  var imageWidth = nextImage.width;
  var imageHeight = nextImage.height;
  var windowWidth = imageWidth + 200;
  var windowHeight = imageHeight;
  var tooWide = false;
  var tooHigh = false;

  if ( windowWidth > maxWidth ) {
    tooWide = true;
    windowWidth = maxWidth;
  }
  if ( windowHeight > maxHeight ) {
    tooHigh = true;
    windowHeight = maxHeight;
  }

  if ( ( windowImage != null ) && !windowImage.closed ) {
    // Close window first
    windowImage.close();
  }

  var scrollbarVisible = ( tooWide || tooHigh );
  var properties = "resizable=1,toolbar=0,scrollbars=" + ( scrollbarVisible ? 1 : 0 ) + ",width=" + windowWidth + ",height=" + windowHeight;

  windowImage = open( "", "windowImage", properties );
	imageName = nextImage.src.substring(nextImage.src.lastIndexOf("/")+1,nextImage.src.length);
  windowImage.document.write( '<html><head><title>'
    + 'Deine E-Card'
    + '</title></head>'
    + '<body topmargin=0 leftmargin=0 marginheight=0 marginwidth=0 bgcolor="#212C54">'
    + '<img src="'
    + nextImage.src
    + '" width="' + imageWidth
    + '" height="' + imageHeight + '">'
    + '<div style="position: absolute; top: 33px; left: ' + (imageWidth + 20) + 'px; width: 160px; padding: 2px; font-family: Arial, Helvetica, sans-serif; font-size: 11px; font-weight: normal; color: #ffffff">'
    + txttype
		+ '<br><br>'
    + '<a href="#" onClick="window.close(); return false;" style="font-family: Arial, Helvetica, sans-serif; font-size: 12px; font-weight: normal; color: #ffffff; text-decoration: none"><img border="0" width="9" height="7" src="/shared/white_arrow.gif"><strong>Discover the<br><img border="0" width="9" height="7" src="/s.gif">BACARDI World</strong></a>'
    + '</div>'
    + '</body>' );
	windowImage.moveTo(30,50);	
	windowImage.focus();
}
