// Function: Preload Images
// Preloads a variable number of images into the document object as hashed
// images.  These images may later be referenced directly for image info.

function PreloadImages() {

   if (document.images) {

      // Create hashed preloaded array right in document object.

      if (!document.preloaded)
         document.preloaded = new Array;

      // Preload the images into hashed array slots we can reference.

      for (var i=0; i<PreloadImages.arguments.length; i++) {
         var strName = PreloadImages.arguments[i];
         if (strName.indexOf( "#" ) != 0) {
            document.preloaded[strName] = new Image;
            document.preloaded[strName].src = strName;
         }
      }

   }

}


// Function: Show Image
// Displays a preloaded document image in another window.

function ShowImage( strImage ) {

   // Sanity check to make sure the image really is preloaded in the document.
   // If it's not, the rest of the logic will not work.

   if (document.preloaded[strImage] == undefined) {
      alert( 'Error: Attempt to use an image not defined in the document!' );
      return;
   }

   // Contruct URL for page used to display image using image attributes.

   var intWidth  = document.preloaded[strImage].width;
   var intHeight = document.preloaded[strImage].height;

   strURL = 'showimage.html'
          + '?img='    + escape( strImage )
          + '&width='  + intWidth
          + '&height=' + intHeight;

   // Open new window to show image and bring focus to the new window.

   var wdwImage = PlainWindow( strURL, '_image', intWidth, intHeight, 0 );
   wdwImage.focus();

}


// Function: Plain Window
// Opens a "plain window" -- a new browser instance with no toolbars, etc. of
// a specific width and height and returns the window instance to the caller.

function PlainWindow( strURL, strName, intWidth, intHeight, blnScrollBars ) {

   var objWindow = window.open( strURL, strName,
      'toolbar=0,'     +
      'location=0,'    +
      'directories=0,' +
      'status='        + blnScrollBars + ',' +
      'menubar=0,'     +
      'scrollbars='    + blnScrollBars + ',' +
      'resizable=1,'   +
      'width='         + intWidth + ',' +
      'height='        + intHeight
   );

   return objWindow;

}
