/*

  PHOTO GALLERY
  photoGallery.js
  deborah lee soltesz
  23 october 2002

  HISTORY
  -------
  23 oct 2002   dls   Original version adapted from previous work by deborah lee soltesz


  DESCRIPTION
  -----------
  This script runs a framed photo gallery consisting
  of a menu, navigation, and thumbnail panel. Medium
  resolution images are displayed in a "slide show" mode, and
  corresponding high resolution images are linked on each medium
  resolution image page.

  The script depends upon the frames having specific names,
  as in the following example frame container index.html:


      <FRAMESET COLS="200,*">
        <FRAME SCROLLING=AUTO SRC="menu.html" NAME="astroGalleryMenu">
        <FRAMESET ROWS="*,50">
          <FRAME SCROLLING=AUTO SRC="thumbs.html" NAME="astroGalleryContent">
          <FRAME SCROLLING=NO SRC="nav.html" NAME="astroGalleryNavigation">
        </FRAMESET>
      </FRAMESET>

  Additionally, the script depends on a second script, photoGalleryListing.js,
  which contains a two dimensional array of image information. The image information
  is gleaned from the images using imageN digital image management software. The format
  of the listing script is:


  imgArr = new Array(
     new Array(filename, caption or comment, image width,image height,date and time, source or photographer, event name),
     new Array(filename, caption or comment, image width,image height,date and time, source or photographer, event name),
     ...
     new Array(filename, caption or comment, image width,image height,date and time, source or photographer, event name)
  );

  e.g.


  imgArr = new Array(
     new Array("RedBailey.JPG", "Red Bailey", "100", "133", "9/25/02 17:47", "Jody Swann", "Reunion Party"),
     new Array("JoeOConnor_KristaEdmonds_RobinMadden.JPG", "Joe O'Connor, Krista Edmonds, and Robin Madden", "177", "133", "9/25/02 17:56", "Jody Swann", "Reunion Party"),
     new Array("BillMuehlberger_Gordon_Lee Silver.jpg", "Bill Muehlberger, Gordon Swann, and Lee Silver", "100", "133", "9/25/02 18:07", "Jody Swann", "Reunion Party"),
     new Array("DSCN0764.JPG", "Ceremony site in front of Shoemaker building ", "177", "133", "9/26/02 9:30", "Jeff Coleman", "Dedication Ceremonies"),
     new Array("DSCN0765.JPG", "Coconino H.S. Chamber Choir preparing for their performance", "177", "133", "9/26/02 9:40", "Jeff Coleman", "Dedication Ceremonies")
  );

*/

curImage = -1 ;

baseURLlo    = "med/" ;
baseURLhi    = "full/" ;

filename     = 0 ;
comment      = 1 ;
filewidth    = 2 ;
fileheight   = 3 ;
datetime     = 4 ;
photographer = 5 ;
eventtitle   = 6 ;

numImages = imgArr.length ;


function writeImageMenuLinks () {
   document.write ("<div>\n");
   for (i = 0 ; i < numImages ; i++) {
     document.write ( " <a href=\"javascript:parent.astroGalleryNavigation.setImage(" + i + ");\">" +
                      "<strong>" + (i + 1) + ") "  +  "</strong>" +
                      imgArr[i][comment] + "</a><br><br>\n" ) ;
   }
   document.write ("</div>\n");
}


function writeImageThumbLinks () {
   document.write("<tr>") ;

   for (i = 0 ; i < numImages ; i++) {
     document.write ("<td align=center valign=top>") ;
     document.write ("<a href=\"javascript:parent.astroGalleryNavigation.setImage(" + i + ");\">\n" );
     document.write ("<img src=\"" + "thumbs/" + imgArr[i][filename] +
                     "\" height=" + imgArr[i][fileheight] + " width=" + imgArr[i][filewidth] +
                     "width=" + imgArr[i][fileheight] + " alt=\"Image Filename: " + imgArr[i][filename] + "\"></a>\n" ) ;
     document.write ( "<p>" + (i + 1) + ") " + imgArr[i][eventtitle] + "<br><a href=\"javascript:parent.astroGalleryNavigation.setImage(" + i + ");\">" +
                      imgArr[i][comment] + "</a></p>\n" ) ;

     if (i % 3 == 2) {
        document.write ("</tr>\n<tr>") ;
     }
   }
}



function writeTextList () {
  document.write("<tr>") ;
  document.write ("<th>") ;
  document.write ("File Name");
  document.write ("</th>") ;
  document.write ("<th>") ;
  document.write ("Event");
  document.write ("</th>") ;
  document.write ("<th>") ;
  document.write ("Caption");
  document.write ("</th>") ;
  document.write ("<th>") ;
  document.write ("Source");
  document.write ("</th>") ;
  document.write ("<th>") ;
  document.write ("Date/Time");
  document.write ("</th>") ;
  document.write ("</tr>\n") ;

  for (i = 0 ; i < numImages ; i++) {
    document.write("<tr valign=top>") ;
    document.write ("<td>") ;
    document.write (imgArr[i][filename]);
    document.write ("</td>") ;
    document.write ("<td>") ;
    document.write (imgArr[i][eventtitle]);
    document.write ("</td>") ;
    document.write ("<td>") ;
    document.write (imgArr[i][comment]);
    document.write ("</td>") ;
    document.write ("<td>") ;
    document.write (imgArr[i][photographer]);
    document.write ("</td>") ;
    document.write ("<td>") ;
    document.write (imgArr[i][datetime]);
    document.write ("</td>") ;
    document.write ("</tr>\n") ;
  }
}


function writeImagePage () {

  displayImage = new Image ;
  displayImage.src = baseURLlo + imgArr[curImage][filename] ;

  parent.astroGalleryContent.document.open() ;
  parent.astroGalleryContent.document.write (
    "<html><head><title>USGS Astro Photo Gallery</title>\n" +
    "<link rel=\"stylesheet\" type=\"text/css\" href=\"assets/styles/main.css\">" +
    "</head><body>\n" +

    "<div align='center'>\n" +
    "  <img class=\"blackBorderedImage\" src=\"" + baseURLlo + imgArr[curImage][filename] + "\" "
  );

  displayImageWidth  = displayImage.width ;
  displayImageHeight = displayImage.height ;

  if (displayImageWidth > 0 && displayImageHeight > 0) {
    parent.astroGalleryContent.document.write (
             "width=" + displayImageWidth + " height=" + displayImageHeight + " "
    );
  }

  parent.astroGalleryContent.document.write (
           "alt=\"" + imgArr[curImage][comment] + "\"><br>\n" +
    "<span style=\"font-weight:bold;\">\n" +
    (curImage + 1) + ") " +
    imgArr[curImage][comment] + "\n" +
    "</span><br><br>\n" +

    "Event: \n" +
    imgArr[curImage][eventtitle] + "<br>\n" +

    "Date: \n" +
    imgArr[curImage][datetime] + "<br>\n" +

    "Source: \n" +
    imgArr[curImage][photographer] + "<br><br>\n" +

    "Filename: \n" +
    imgArr[curImage][filename] + "<br>\n" +

    "<a href=\"" + baseURLhi + imgArr[curImage][filename] + "\">\n" +
    "Download high resolution image</a>\n" +
    "<br>\n" +

    "</div>\n" +

    "</body></html>"
  );
  parent.astroGalleryContent.document.close() ;
}

function setImage (new_curImage) {
  curImage = new_curImage ;
  writeImagePage () ;
}

function showNext () {
  curImage = ++curImage % numImages ;
  writeImagePage () ;
}


function showPrev () {
  curImage = (--curImage + numImages) % numImages ;
  writeImagePage () ;
}

function reset () {
  curImage = -1 ;
}
