  // *****************************************
  // 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
  // *****************************************


  // 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 ;
  stillWidth  =  3 ;
  stillHeight =  4 ;
  stillSize   =  5 ;
  imageWidth  =  6 ;
  imageHeight =  7 ;
  imageSize   =  8 ;
  QTVR_Size   =  9 ;
  comment     = 10 ;

  panMediaArr = new Array (
    //         filename       thumb info  still info        image info          QTVR      comment
    //         ------------   ----------  --------------    ----------------    -----     -----------
    new Array ("AP11pan",     250, 38,    1000, 151, "39",    3744, 564,  "336",    "  464",    "Apollo 11"),
    new Array ("AP12pan",     250, 35,    1000, 140, "46",    4224, 592,  "399",    "  542",    "Apollo 12"),
    new Array ("AP14_B1",     250, 31,    1000, 124, "27",    4000, 496,  "306",    "9,403",    "Apollo 14"),
    new Array ("AP14_C",      250, 38,    1000, 151, "39",    4224, 636,  "417",    "1,698",    "Apollo 14"),
    new Array ("ap14_F",      250, 32,    1000, 126, "29",    4000, 506,  "275",    "3,913",    "Apollo 14"),
    new Array ("ap14_G",      250, 31,    1000, 124, "24",    4000, 496,  "243",    "3,540",    "Apollo 14"),
    new Array ("ap14_H",      250, 35,    1000, 138, "29",    4000, 553,  "305",    "4,236",    "Apollo 14"),
    new Array ("AP15_2",      250, 43,    1000, 181, "30",    4000, 723,  "432",    "7,541",    "Apollo 15"),
    new Array ("AP15_7",      250, 34,    1000, 164, "32",    1587, 260,  " 61",    "1,543",    "Apollo 15"),
    new Array ("AP15_8",      250, 30,    1000, 129, "27",    4224, 544,  "353",    "1,642",    "Apollo 15"),
    new Array ("AP15_9",      250, 32,    1000, 152, "29",    1584, 240,  " 59",    "1,760",    "Apollo 15"),
    new Array ("AP15ALSE",    250, 37,    1000, 161, "43",    1584, 255,  " 66",    "1,924",    "Apollo 15"),
    new Array ("AP15_LMe",    250, 27,    1000, 147, "37",    4224, 620,  "333",    "1,642",    "Apollo 15"),
    new Array ("AP15_LMn",    250, 29,    1000, 140, "30",    4224, 592,  "309",    "1,339",    "Apollo 15"),
    new Array ("AP15LMt",     250, 30,    1000, 115, "34",    4320, 496,  "304",    "1,300",    "Apollo 15"),
    new Array ("AP16_1",      250, 38,    1000, 148, "28",    4608, 684,  "558",    "1,958",    "Apollo 16"),
    new Array ("AP16_2",      250, 42,    1000, 163, "35",    1586, 259,  " 83",    "2,019",    "Apollo 16"),
    new Array ("AP16_4",      250, 48,    1000, 234, "37",    4704, 1100, "713",    "3,361",    "Apollo 16"),
    new Array ("AP16_4b",     250, 40,    1000, 167, "39",    1584, 264,  " 74",    "1,969",    "Apollo 16"),
    new Array ("AP16_5",      250, 35,    1000, 168, "36",    1585, 267,  " 66",    "1,756",    "Apollo 16"),
    new Array ("AP16_8",      250, 37,    1000, 155, "33",    1583, 246,  " 72",    "1,972",    "Apollo 16"),
    new Array ("AP16_10",     250, 41,    1000, 191, "42",    4608, 880,  "534",    "2,236",    "Apollo 16"),
    new Array ("AP16_11",     250, 47,    1000, 308, "48",    4704, 1448, "858",    "4,775",    "Apollo 16"),
    new Array ("AP16_13",     250, 28,    1000, 147, "40",    1588, 233,  " 51",    "1,517",    "Apollo 16"),
    new Array ("AP16ALSE",    250, 39,    1000, 152, "38",    4608, 700,  "531",    "1,933",    "Apollo 16"),
    new Array ("AP16LMe",     250, 36,    1000, 164, "41",    4608, 756,  "490",    "1,848",    "Apollo 16"),
    new Array ("AP16LMn",     250, 33,    1000, 148, "47",    1586, 234,  " 63",    "1,494",    "Apollo 16"),
    new Array ("Ap17_1",      250, 34,    1000, 140, "34",    4512, 632,  "376",    "1,439",    "Apollo 17"),
    new Array ("AP17_2",      250, 39,    1000, 177, "39",    4320, 764,  "403",    "1,624",    "Apollo 17"),
    new Array ("AP17_2NE",    250, 42,    1000, 208, "42",    4800, 1000, "679",    "2,519",    "Apollo 17"),
    new Array ("AP17_3",      250, 53,    1000, 260, "53",    2304, 600,  "201",    "  785",    "Apollo 17"),
    new Array ("AP17_4",      250, 36,    1000, 146, "36",    2304, 336,  "130",    "  501",    "Apollo 17"),
    new Array ("AP17_4b",     250, 52,    1000, 226, "52",    4512, 1020, "570",    "2,148",    "Apollo 17"),
    new Array ("AP17_5",      250, 41,    1000, 145, "41",    4405, 639,  "535",    "1,934",    "Apollo 17"),
    new Array ("AP17_6",      250, 51,    1000, 204, "51",    4224, 860,  "547",    "2,168",    "Apollo 17"),
    new Array ("AP17_7",      250, 33,    1000, 164, "33",    4704, 772,  "477",    "2,300",    "Apollo 17"),
    new Array ("ap17_8",      250, 35,    1000, 156, "35",    4512, 704,  "467",    "2,055",    "Apollo 17"),
    new Array ("AP17_9",      250, 57,    1000, 294, "57",    4800, 1412, "867",    "3,930",    "Apollo 17")
  );

  numFiles = panMediaArr.length ;

  // base paths for various media
  thumbsBase  = "media/thumbs/" ;
  stillsBase  = "media/stills/" ;
  imageBase   = "media/images/" ;
  QTVR_Base   = "media/QTVR/"   ;
  captionBase = "captions/"     ;
  JavaBase    = "media/java/"   ;

  // window size for each object
  stillsWinWidth  = 500 ;
  stillsWinHeight = 300 ;

  imageWinWidth  = 600 ;
  imageWinHeight = 500 ;

  QTVR_WinWidth  = 400 ;
  QTVR_WinHeight = 300 ;

  JavaWinWidth  = 600 ;
  JavaWinHeight = 400 ;


  // caption window width will match the media window width
  captionWinHeight = 300 ;

  // padding to add to window around media object
  paddingWidth  = 30 ;
  paddingHeight = 90 ;


  // 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 = panMediaArr[selection][filename] ;

    if (mediaType == "still") {
      basePath       = stillsBase                           ;
      mediaWinWidth  = stillsWinWidth                       ;
      mediaWinHeight = panMediaArr[selection][stillHeight] ;
      mediaExtension = ".jpg"                              ;
    }
    else if (mediaType == "image") {
      basePath       = imageBase      ;
      mediaWinWidth  = imageWinWidth  ;
      mediaWinHeight = imageWinHeight ;
      mediaExtension = ".jpg"         ;
    }
    else if (mediaType == "QTVR") {
      basePath       = QTVR_Base      ;
      mediaWinWidth  = QTVR_WinWidth  ;
      mediaWinHeight = QTVR_WinHeight ;
      mediaExtension = ".mov"         ;
    }
    else if (mediaType == "Java") {
      basePath       = JavaBase       ;
      mediaWinWidth  = JavaWinWidth   ;
      mediaWinHeight = JavaWinHeight  ;
      mediaExtension = ".html"             ;
    }

    winHeight = mediaWinHeight + captionWinHeight + paddingHeight ;
    winWidth  = mediaWinWidth + paddingWidth ;

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

    // need to add noframes to this
    Panorama.document.write( "<html>\n<head>\n<title>USGS Astrogeology: Lunar Panorama " +
                        panMediaArr[selection][filename] + "</title>\n</head>" +

                        "<FRAMESET ROWS=\"" + (mediaWinHeight + paddingHeight) + ",*\">\n" +
                        "  <FRAME SRC=\"" + basePath + mediaSelection + mediaExtension + "\" NAME=\"mediaFrame\">\n" +
                        "  <FRAME SRC=\"" + captionBase + mediaSelection + ".html\" NAME=\"captionFrame\">" +
                        "</FRAMESET>" +
                        "</html>"
                      ) ;

    Panorama.focus() ;

  }

  // WRITE JAVA PAGE
  // writes applet code into the page containing the java
  // panorma media presentation

  function writeJavaPage (containerName) {
    selection = 0 ;
    for (i = 0 ; i < numFiles ; i++) {
      if (containerName == panMediaArr[i][filename] ) {
        selection = i ;
        break ;
      }
    }
    document.write(
      "  <applet code=\"pmvr.class\" width=" + JavaWinWidth + " height=" + JavaWinHeight + ">" +
      "    <param name=\"image\" value=\"../../" + imageBase + panMediaArr[selection][filename] + ".jpg\">" +
      "    <param name=\"view\" value=360>" +
      "    <param name=\"auto\" value=5>" +
      "    <param name=\"background\" value=\"000000\">" +
      "    <param name=\"vcenter\" value=" + (panMediaArr[selection][imageHeight] * .5) + ">" +
      "  </applet>"
    ) ;
  }

  // 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") ;
    document.write("  <tr bgcolor='#CCFFFF'>\n") ;
    document.write("    <th class=captionTitleDefault>Thumbnail</th>\n") ;
    document.write("    <th class=captionTitleDefault>QTVR</th>\n") ;
//    document.write("    <th class=captionTitleDefault>Java</th>\n") ;
    document.write("    <th class=captionTitleDefault nowrap>Small Still</th>\n") ;
    document.write("    <th class=captionTitleDefault nowrap>Large Still</th>\n") ;
    document.write("  </tr>\n") ;

    for (i = 0 ; i < numFiles ; i++) {
      document.write("  <tr bgcolor='#CCFFFF'>\n") ;
      // table header
      document.write("    <td class=captionDefault align=center>\n") ;
      document.write("      <img border=1 src=\"" + thumbsBase + panMediaArr[i][filename] + ".jpg\"" +
                           " width=" + panMediaArr[i][thumbWidth] + " height=" + panMediaArr[i][thumbHeight] +
                           " alt='Panorama: " + panMediaArr[i][comment]  + "'><br><strong>\n") ;
      document.write(      panMediaArr[i][comment] + " <br>File:</strong> " + panMediaArr[i][filename] ) ;
      document.write("    </td>\n") ;

      // QTVR
      document.write("    <td class=captionDefault align=center>\n") ;
      document.write("      <a href='javascript:createPopUpDisplay(\"QTVR\", " + i + ")'>" + panMediaArr[i][QTVR_Size] + " kB</a>") ;
      document.write("    </td>\n") ;

      // Java
//      document.write("    <td class=captionDefault align=center>\n") ;
//      document.write("      <a href='javascript:createPopUpDisplay(\"Java\", " + i + ")'>" + panMediaArr[i][imageSize] + " kB</a>") ;
//      document.write("    </td>\n") ;

      // Stills
      document.write("    <td class=captionDefault align=center>\n") ;
      document.write("      <a href='javascript:createPopUpDisplay(\"still\", " + i + ")'>" + panMediaArr[i][stillWidth] + "x" +
                             panMediaArr[i][stillHeight] + "<br>" + panMediaArr[i][stillSize] + " kB</a>") ;
      document.write("    </td>\n") ;

      // Images
      document.write("    <td class=captionDefault align=center>\n") ;
      document.write("      <a href='javascript:createPopUpDisplay(\"image\", " + i + ")'>" + panMediaArr[i][imageWidth] + "x" +
                             panMediaArr[i][imageHeight] + "<br>" + panMediaArr[i][imageSize] + " kB</a>") ;
      document.write("    </td>\n") ;
      document.write("  </tr>\n") ;

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

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

  }

