// talk_slides.js
// 
// navigation for slides in GBdirect talks
// 
// assumptions:
//   * The page initially loads in slides list view, using a style-sheet with
//     id="SlidesListStylesheet".
//   * There is an alternative style-sheet for the slideshow view, with
//     id="SlideshowStylesheet".
//   * There is something which runs SwitchToSlideshow() to switch from the
//     slides list view to the slideshow view.
//   * Every slide is a block with class="Slide", and initially has display:
//     none.
//   * Each slide is numbered consecutively with id="S1", id="S2", ...
//   * The contents of the splash screen is in a block with id="Splash", which
//     initially has display: block;
//   * There is a block with id="BreakAlert", which initially has display:
//     none.
//   * <img> elements initially have their sources set to sources for the
//     slides list view, with filenames such as 2h_foo.png.  Images for the
//     slideshow view exist with filenames such as 2d_foo.png (replacing the
//     "h" with "d" after the number).  The dimensions of the slideshow images
//     are stored in the SlideShowImageWidth and SlideShowImageHeight arrays,
//     with indices corresponding to the numbers in the filenames.
// 
// by Smylers <smylers@gbdirect.co.uk>
// 
// 2003 May 11:  initial version
// 2003 May 17:  function for switching to slideshow after loading
// 2003 Jun 11:  adjust image sizes when switching views
// 
// This file is placed in the public domain.  You may do what you wish with it.


// Include the common slide navigation, keeping navigation disabled (while in
// the slide list view) until specifically activated (by switching to the
// slideshow view):
var NavigationEnabled = false;
document.write('<script src="slides.js" type="text/javascript"></script>');


function SwitchToSlideshow()
// switches to the slideshow view and enables the JavaScript navigation
{

  // Swap the style-sheets:
  document.getElementById('SlidesListStylesheet').disabled = true;
  document.getElementById('SlideshowStylesheet').disabled = false;

  // The images in the slides will have shrunken ('half-size') dimensions to
  // fit into the slide list view.  Replace each one with an equivalent
  // ('double-size') suitable for the slideshow view:
  for (var i = 0; i < document.images.length; i++) with (document.images[i])
  {

    // A half-size image has a names such as 2h_foo.png.  This could be
    // transformed to the double-size version using String.replace, but there
    // doesn't seem to be any way of getting the values of $1 et al out of that
    // method (for use below with the sizes).  So instead grab all the parts of
    // the complete path, for reconstituting by hand:
    var Matched = src.match(/^(.*\/)(\d+)h(_[^\/]+)$/);

    // Only continue if this is indeed an image from a slide, not a standard
    // part of the formatting:
    if (Matched)
    {

      // The double-size filename is like the half-size one but with 'd'
      // instead of 'h':
      src = Matched[1] + Matched[2] + 'd' + Matched[3];

      // Remove the title, which indicates that the image can be zoomed in in
      // the slide-list view:
      title = '';

      // Set the dimensions for the double-size version, which will be stored
      // in a couple of arrays in the page, indexed by image number:
      width = SlideShowImageWidth[Matched[2]];
      height = SlideShowImageHeight[Matched[2]];
    }

  } // loop through each image

  NavigationEnabled = true;

} // SwitchToSlideshow()


var LastSlide = 1;


function Next()
// move to the next screen
{

  if (Splash)
  {
    DisplaySlide(1);
  }
  else
  {
    var NewSlide = CurrentSlide + 1;
    if (document.getElementById('S' + NewSlide))
    {
      DisplaySlide(NewSlide);
    }

    // After the last slide, display the splash screen again, noting the
    // current slide number for the purposes of moving 'backwards' from there
    // to the last slide in the future:
    else
    {
      LastSlide = CurrentSlide;
      DisplaySplash();
    }
  }

} // Next()


function Prev()
// move to the previous screen
{

  if (Splash)
  {
    DisplaySlide(LastSlide);
  }
  else if (CurrentSlide == 1)
  {
    DisplaySplash();
  }
  else
  {
    DisplaySlide(CurrentSlide - 1);
  }

} // Prev()


function GotoModule()
// dummy for talks
{ }
