  // *****************************************
  // SCRIPT:   Pan Gallery
  // Filename: panGallery.js
  // Purpose:  script to write links to and pages
  //           for various multimedia displays of
  //           the Apollo panoramas from the
  //           "Atlas of the Moon" CD-ROM project
  //
  // Author:   Deborah Lee Soltesz, USGS, 01/2002
  // *****************************************

  // browser checks
  ns4    = (document.layers) ? true:false ;
  ns6    = (document.getElementById) ? true:false ;
  isNav  = (navigator.appName.indexOf("Netscape")  != -1)
  isMSIE = (navigator.appName.indexOf("Microsoft") != -1)

  // list of multimedia file names (without extensions), and
  // image width/height for thumbs, small stills, and full-sized images.

  // index array aliases
  filename    =  0 ;
  thumbWidth  =  1 ;
  thumbHeight =  2 ;
  medWidth  =  3 ;
  medHeight =  4 ;
  medSize   =  5 ;
  fullWidth  =  6 ;
  fullHeight =  7 ;
  fullSize   =  8 ;
  comment     =  9 ;


  numFiles = MediaArr.length ;

  // base paths for various media
  thumbsBase  = "thumbs/" ;
  medBase     = "med/" ;
  fullBase    = "full/" ;

  // window size for each object
  medWinWidth  = 500 ;
  medWinHeight = 300 ;

  fullWinWidth  = 600 ;
  fullWinHeight = 500 ;


  // storage variables
  basePath       = "" ;
  mediaWinWidth  = 0  ;
  mediaWinHeight = 0  ;
  mediaExtension = "" ;


  // CREATE POP UP DISPLAY
  // this function is an href in the table of links.
  // creates a window with two frames, one with the caption file
  // the other with the media object (QTVR, Java, image, etc.)

  function createPopUpDisplay (mediaType, selection) {

    mediaSelection = MediaArr[selection][filename] ;
    scrollingWin = 0 ;

    if (mediaType == "med") {
      basePath       = medBase                        ;
      mediaWinWidth  = MediaArr[selection][medWidth]  ;                       ;
      mediaWinHeight = MediaArr[selection][medHeight] ;
    }
    else if (mediaType == "full") {
      basePath       = fullBase      ;
      mediaWinWidth  = fullWinWidth  ;
      mediaWinHeight = fullWinHeight ;
      scrollingWin = 1 ;
    }

    winHeight = mediaWinHeight + 30 ;
    winWidth  = mediaWinWidth  + 20 ;

    // if window is already open, resize or reopen it to fit
    // new media object (depending on the browser)
    if (window["PhotoWin"] && window["PhotoWin"].closed == false) {
      PhotoWin = window["PhotoWin"] ;
      PhotoWin.close() ;
    }
    PhotoWin = open(basePath + mediaSelection,"PhotoWin","toolbar=0,location=0,status=0,menubar=0,scrollbars=" + scrollingWin +
                    ",resizable=1,width=" + winWidth + ",height=" + winHeight);

    PhotoWin.focus() ;

  }


  // WRITE TABLE OF LINKS
  // writes a table of links to the various media types
  // for each item in the presentation

  function writeTableOfLinks () {
    document.write("<table width='600'>\n") ;
    document.write("  <tr>\n") ;
    document.write("    <td bgcolor='#99CCCC'>\n") ;

    document.write("<table width='100%' cellpadding=5 cellspacing=5>\n") ;

    for (i = 0 ; i < numFiles ; i++) {
      if (i % 3 == 0) {
        document.write("  <tr bgcolor='#CCFFFF'>\n") ;
      }
      // table header
      document.write("    <td class=captionDefault align=center valign=top>\n") ;
      document.write("       <a href='javascript:createPopUpDisplay(\"med\", " + i + ")'>") ;
      document.write("      <img border=1 src=\"" + thumbsBase + MediaArr[i][filename] + "\"" +
                           " width=" + MediaArr[i][thumbWidth] + " height=" + MediaArr[i][thumbHeight] +
                           " alt='Panorama: " + MediaArr[i][comment]  + "'></a>\n<p><strong>\n") ;
      document.write(      MediaArr[i][comment] + " <p>File:</strong> " + MediaArr[i][filename] ) ;

      // Stills
      document.write("      <br><a href='javascript:createPopUpDisplay(\"med\", " + i + ")'>" + MediaArr[i][medWidth] + "x" +
                             MediaArr[i][medHeight] + ", " + MediaArr[i][medSize] + " kB</a>") ;

      // Images
      document.write("      <br><a href='javascript:createPopUpDisplay(\"full\", " + i + ")'>" + MediaArr[i][fullWidth] + "x" +
                             MediaArr[i][fullHeight] + ", " + MediaArr[i][fullSize] + " kB</a>") ;
      document.write("    </td>\n") ;
      if (i % 3 == 2) {
        document.write("  </tr>\n") ;
      }

    }
    document.write("</table>\n") ;

    document.write("    </td>\n") ;
    document.write("  </tr>\n") ;
    document.write("</table>\n") ;

  }

