
  // SCRIPT:   Image Map Pop-up
  // Filename: imageMapPop.js
  // Purpose:  Script to handle an image map of thumbnails that
  //           "pops up" a larger view (~200 x 200) of the image on rollover
  //           and a super-sized view (max 800x600) on click
  //
  // Author:   Deborah Lee Soltesz, USGS, 4/2002



  // Use with UTILITY.JS
  // make sure to include utility.js to get the playEventSound function
  // as well as a few other important functions


      //DEFINED: in the HTML file
      //baseURL_thumb = "images/thumbs/" ;
      //baseURL_super = "images/" ;

      offsetLeft = 0 ;
      offsetTop = 0 ;

      filename      = 0 ;
      rolloverSound = 1 ;
      popUpSound    = 2 ;
      imgWidth      = 3 ;
      imgHeight     = 4 ;

      tinyRX = 5 ;
      tinyTY = 6 ;
      tinyLX = 7 ;
      tinyBY = 8 ;


      // DEFINED: image map array defined in the HTML file
      //imgArr = new Array (
      //    new Array ("anaglyph_ap16_17961st_fs", "clickonSound",  "popSound",  473, 405, 233,8,304,72    ),
      //    ...
      //    new Array ("ap17_LMRover_fs",          "clickonSound",  "popSound",  608, 375, 159,88,262,155  )
      //  ) ;


      // CHANGE IMAGE
      // changes the URL for the image given by 'imageID' to the image URL described by
      // imgArr[imageIndex]
      function changeImage (thisLink, imageID, imageIndex) {
        if (!pageLoaded) {
          return ;
        }
        setPosition () ;
        clearImage (imageID) ;
        if (ns6) {

          imageObject = document.getElementById(imageID) ;
          newLeft = (imgArr[imageIndex][tinyLX] + (imgArr[imageIndex][tinyRX] - imgArr[imageIndex][tinyLX]) / 2 - 150 + offsetLeft) ;
          imageObject.style.left  = newLeft ;

          newTop  = (imgArr[imageIndex][tinyTY] + (imgArr[imageIndex][tinyBY] - imgArr[imageIndex][tinyTY]) / 2 - 75  + offsetTop ) ;
          imageObject.style.top = newTop ;

          imageObject.style.zIndex = 2 ;
          imageObject.src = baseURL_thumb + imgArr[imageIndex][filename] + ".gif" ;
          imageObject.title = thisLink.title ;
          imageObject.style.visibility = "visible" ;
        }
        else {
          imageObject = document.images[imageID] ;
          imageObject.src = baseURL_thumb + imgArr[imageIndex][filename] + ".gif" ;
          imageObject.alt = thisLink.title ;
          imageObject.visibility = "visible" ;
        }
        changeLink (thisLink, imageIndex) ;

        if (isMSIE) {
          changeLink (document.links("thumbLink"), imageIndex) ;

        }
        else if (ns6) {
          changeLink (document.links["thumbLink"], imageIndex) ;
        }
        playEventSound (imgArr[imageIndex][rolloverSound]) ;
      }


      // CLEAR IMAGE
      // clear the pop-up image from the screen by cramming it behind everything else
      // and "hiding" it
      function clearImage (imageID) {
        if (ns6) {
          imageObject = document.getElementById(imageID) ;
          imageObject.style.zIndex = 0 ;
          imageObject.style.visibility = "hidden" ;
        }
        else {
          imageObject = document.images[imageID] ;
          imageObject.src = baseURL_thumb + "blank.gif" ;
        }
      }

      // CHANGE LINK
      // changes a link to use the pop-up window function,
      // the default definition of the link should be compatible
      // with non-script browsers
      function changeLink (thisLink, imageIndex) {
        thisLink.href = "javascript:popUpImage(" + imageIndex + ");" ;
      }


      // POP UP IMAGE
      // assembles page-specific information into a call to
      // the standard utility.js function call, and plays
      // an event sound for the pop-up window
      function popUpImage (imageIndex) {
        m_url = baseURL_super + imgArr[imageIndex][filename] + ".jpg" ;
        w = imgArr[imageIndex][imgWidth] + 30 ;
        h = imgArr[imageIndex][imgHeight] + 30  ;
        popUpWindow (m_url, w, h) ;
        playEventSound (imgArr[imageIndex][popUpSound]) ;
      }


      // SET POSITION
      // Figures out where the main image map is and sets the offset
      // for the "pop-up" image accordingly
      // --based on info from http://www.xs4all.nl/~ppk/js/findpos.html
      function setPosition () {
        if (ns6) {
          clickableImageMapObj = document.getElementById('clickableImageMap') ;

          curtop = 0 ;
          curleft = 0 ;

          obj = clickableImageMapObj ;
          while (obj.offsetParent)
          {
            curleft += obj.offsetLeft ;
            obj = obj.offsetParent;
          }

          obj = clickableImageMapObj ;
          while (obj.offsetParent)
          {
            curtop += obj.offsetTop ;
            obj = obj.offsetParent;
          }

          offsetTop = curtop ;
          offsetLeft = curleft ;
        }
      }


