  ///////////////////////////////////////////////////////////////////////////
 // No user serviceable parts beyond this point ////////////////////////////
///////////////////////////////////////////////////////////////////////////

var index = 0;  //current slide
var start = 0;  //slide show toggle

var pix_img = new Array(); // a spot to store image names 
var pix_txt = new Array(); // a spot to store descriptions

var pause = 4000; // default value for pause 
var slide;  // setInterval variable

function load_slides() {
  var i = 0;

  //separate image names and associated text
  for (p in pix) {
    pix_txt[i] = pix[p];
    pix_img[i] = p;
    i++;
  }
  //show first slide
  show();
  return;
}

function controls() {
  var norm = pause;
  var slow = pause * 2;
  var fast = pause / 2;
  document.writeln('<form name="control">');
  document.writeln('<table><tr><td align=center>');
  document.writeln('<input type=button onClick="javascript:view(\'first\')" value="&nbsp;|&lt;&nbsp;">');
  document.writeln('<input type=button onClick="javascript:view(\'prev\')" value="&nbsp;&lt;-&nbsp;">');
  document.writeln('<input type=button onClick="javascript:view(\'next\')" value="&nbsp;-&gt;&nbsp;">');
  document.writeln('<input type=button onClick="javascript:view(\'last\')" value="&nbsp;&gt;|&nbsp;">');
  document.writeln('</td></tr><tr><td align=center>');
  document.writeln('<input type=button name="slide" onClick="javascript:slide_show()" value="Auto Slide Show">');
  document.writeln('</td></tr><tr><td align=center>');
  document.writeln('<input type="radio" name="speed" onClick="pause='+slow+'">Slow');
  document.writeln('<input type="radio" name="speed" onClick="pause='+norm+'" checked>Normal');
  document.writeln('<input type="radio" name="speed" onClick="pause='+fast+'">Fast');
  document.writeln('</td></tr></table>');
  document.writeln('</form>');
  return;
}

function show() {
  // compose the HTML that will show the appropriate image
  var to_show = '<a href="'+pix_img[index]+'" target="bigpicture">';
  to_show += '<img border="0" src="'+pix_img[index]+'" ';
  if (pix_height > 0) {
    to_show += 'height="'+pix_height+'" ';
  }
  to_show += 'alt="Click for a full-size view of '+pix_img[index]+'"></a>';
  to_show += '<br>'+pix_txt[index];

  //Netscape 4 and up
  if (document.layers) {
    document.ns4outer.document.ns4inner.document.write(to_show); 
    document.ns4outer.document.ns4inner.document.close(); 
    return;
  } 
  //Internet Explorer 4 and up
  if (document.all) {
    document.all.slides.innerHTML = to_show;
    return;
  } 
  //Document Object Model (Netscape 6, Mozilla)
  if (document.getElementById) {
    range = document.createRange();
    element = document.getElementById("slides");
    range.setStartBefore(element);
    htmlFragment = range.createContextualFragment(to_show);
    while (element.hasChildNodes())
      element.removeChild(element.lastChild);
    element.appendChild(htmlFragment);
    return;
  }
  return;
}

function view(choice) {
  if (start == 1 && choice != "slide") { stop_show(); }
  if (choice == "next" || choice == "slide") {
    index++;
    if (index >= pix_img.length) {
      index = 0;
    }
    if (choice == "slide") { slide = setTimeout('view("slide")', pause); }
  }
  if (choice == "prev") {
    index--;
    if (index < 0) {
      index = pix_img.length - 1;
    }
  }
  if (choice == "first") { index = 0; }
  if (choice == "last") { index = pix_img.length - 1; }
  // if (anything_else) { do_nothing(); } 
  show();
}

function start_show() {
  start = 1;                       // slide show in progress;
  view('slide');                   // show slides
  document.control.slide.value="Stop Slide Show";
}

function stop_show() {
  start = 0;                       // slide show is ended
  clearTimeout(slide);             // stop sliding
  document.control.slide.value="Auto Slide Show";
}

function slide_show() {
  if (start == 0) {
    start_show();
  } else {
    stop_show();
  }
}
