<!-- Begin
// Copyright Realize IT GmbH, www.realize.ch
// Latest Changes
// 2004_06_00   GH new

  var myImg;
      
  function pictureViewer(img, windowWidth, windowHeight, openStr, fit){
    // windowWidth = -1: window will have same dimension as picture 
    // windowHeight = -1: window will have same dimension as picture 
    // openStr = '': program uses own window open-string
    // fit = 'fit': program opens window to exactly fit picture size (with respect to aspect ratio of picture)
    
    myImg = new Image();
    myImg.src = img;

    doWaitForPicture(img, windowWidth, windowHeight, openStr, fit);
  }
  
  
  function doWaitForPicture(img, windowWidth, windowHeight, openStr, fit){
    if (myImg.complete) {
      handlePicture(img, windowWidth, windowHeight, openStr, fit);
    } else {
       var functionParam = "doWaitForPicture('" + img + "', " + windowWidth + ", " + windowHeight + ", '" + openStr + "', '" + fit + "')";
       var interval = setTimeout(functionParam, 500);
    }
  }

  
  function handlePicture(img, windowWidth, windowHeight, openStr, fit) {
    
    // actual picture sizes
    var imgWidth = myImg.width;
    var imgHeight = myImg.height;
  
    // minimum border around the window; 
    // uses by image dimensions >= screen dimensions
    var borderLeft   = 25;
    var borderRight  = 25;
    var borderTop    = 40;
    var borderBottom = 40;
     
    // space for i.e. close button 
    var spaceLeft    = 0;
    var spaceRight   = 0;
    var spaceTop     = 0;
    var spaceBottom  = 0; //30; if you want the close button
     
    var contentWidth = imgWidth + spaceLeft + spaceRight; 
    var contentHeight = imgHeight + spaceTop + spaceBottom;  
     
    var maxWindowWidth = screen.availWidth - borderLeft - borderRight;
    var maxWindowHeight = screen.availHeight - borderTop - borderBottom;

    var isFit = false;
    if (fit == 'fit') isFit = true;
        
    // alert('maxWindowWidth = ' + maxWindowWidth + '; screen.availWidth = ' + screen.availWidth + '; maxWindowHeight = ' + maxWindowHeight + '; screen.availHeight = ' + screen.availHeight);
    
    if (windowWidth == -1) {
      windowWidth = contentWidth; 
    }  
    
    if (windowHeight == -1) {
      windowHeight = contentHeight;
    }
    
    // don't allow window dimensions greater as screen
    // image is the object to be resized
    if (windowWidth > maxWindowWidth) {
      windowWidth = maxWindowWidth;
    }
    
    if (windowHeight > maxWindowHeight) {
      windowHeight = maxWindowHeight;
    } 
    
    // find values to open window centered on screen
    var centerX = screen.availWidth/2 - windowWidth/2; 
    var centerY = screen.availHeight/2 - windowHeight/2; 

    // alert('windowWidth = ' + windowWidth + '; windowHeight = ' + windowHeight + '; centerX = ' + centerX + '; centerY = ' + centerY + '; imgWidth = ' + imgWidth + '; imgHeight = ' + imgHeight);
    
    // only shrinking will be supported
    if (isFit) {
      if (contentWidth > windowWidth) {
        imgWidth = imgWidth - (contentWidth - windowWidth);
        if (imgWidth < 0) imgWidth = 0;
        contentWidth = imgWidth + spaceLeft + spaceRight; 
      }
      
      if (contentHeight > windowHeight) {
        imgHeight = imgHeight - (contentHeight - windowHeight);
        if (imgHeight < 0) imgHeight = 0;
        contentHeight = imgHeight + spaceTop + spaceBottom; 
      }
    }
    
    var picScrollbar;
    if ((contentWidth <= windowWidth) && (contentHeight <= windowHeight)) {
      picScrollbar = 'no';
    } else {
      picScrollbar = 'yes';
    }   

    if (openStr.length == 0) openStr = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=' + picScrollbar + ',resizable=yes';
    
    openStr = openStr + ',width=' + windowWidth + ',height=' + windowHeight + ',left=' + centerX + ',top=' + centerY;
    
    openPictureWindow(img, imgWidth, imgHeight, "Picture Viewer", openStr);
  }
  
  
  function openPictureWindow(imageName, imageWidth, imageHeight, alt, openStr) {  
  	var newWindow;
  	newWindow = window.open('','newWindow', openStr);
  	
  	newWindow.document.open();

  	newWindow.document.write('<html><title>'+alt+'</title>');
  	newWindow.document.write('<body bgcolor="#000000" leftmargin="0" topmargin="0" marginheight="0" marginwidth="0" onBlur="self.close()"  oncontextmenu="return false">'); 
    
    if ((imageWidth != 0) && (imageHeight != 0)) {
      newWindow.document.write('<img src=\"' + imageName + '\" width=' + imageWidth + ' height=' + imageHeight + ' alt=\"' + alt + '\">'); 	
  	}
  	
  	//newWindow.document.write('<br><a href="#" onclick="self.close();">Close</a>');

  	newWindow.document.write('</body></html>');

  	newWindow.document.close();
  	
  	newWindow.focus();
  }




//  End -->

