var phototimeout_delay = 3000; // milliseconds
var currentphoto = 0;
var curWidth = 0;
var curHeight = 0;

var photos = new Array(8);
photos[0] = "images/The Bull Inn.jpg";
photos[1] = "images/East Farleigh Shop.jpg";
photos[2] = "images/Outside Church.jpg";
photos[3] = "images/Farleigh Hill.jpg";
photos[4] = "images/Court Lodge.jpg";
photos[5] = "images/Cottage.jpg";
photos[6] = "images/Forge Lane, Dean Street Junction.jpg";
photos[7] = "images/Water Works.jpg";

var titles = new Array(8);
titles[0] = "1/8 The Bull Inn";
titles[1] = "2/8 East Farleigh Shop on the Hill";
titles[2] = "3/8 Outside St Mary's Church";
titles[3] = "4/8 Farleigh Hill";
titles[4] = "5/8 Court Lodge, Lower Road";
titles[5] = "6/8 Cottage, Water Works in background";
titles[6] = "7/8 Forge Lane, Dean Street Junction";
titles[7] = "8/8 Water Works";

var width = new Array(8);
width[0] = 399;
width[1] = 468;
width[2] = 451;
width[3] = 386;
width[4] = 404;
width[5] = 488;
width[6] = 420;
width[7] = 427;

var height = new Array(8);
height[0] = "235";
height[1] = "342";
height[2] = "311";
height[3] = "229";
height[4] = "233";
height[5] = "341";
height[6] = "259";
height[7] = "339";


function nextphoto() {
 resetphototimeout();
 ++currentphoto;
 displayphoto();
}

function previousphoto() {

 resetphototimeout();
 --currentphoto;
 displayphoto();
}

function startstopphoto() {
 var text=document.getElementById('photosbutton').innerHTML
 document.getElementById('photosbutton').innerHTML = (text == "Stop") ? "Start" : "Stop";
 phototimeout();
}


function phototimeout() {
 if (document.getElementById('photosbutton').innerHTML == "Stop") {
  photoTimerId = window.setTimeout("phototimeout()", phototimeout_delay);
  ++currentphoto;
  displayphoto();
 }
}

function resetphototimeout() {
 if (document.getElementById('photosbutton').innerHTML == "Stop") {
  window.clearTimeout(photoTimerId);
  photoTimerId = window.setTimeout("phototimeout()", phototimeout_delay);
 }
}

function displayphoto() {
 if (currentphoto > photos.length-1) {
  currentphoto = 0;
 } if (currentphoto < 0) {
  currentphoto = photos.length-1
 }

  document.images.photoshow.src = photos[currentphoto];
  document.getElementById('phototitle').innerHTML = titles[currentphoto];
  if (width[currentphoto] != curWidth) {
   curWidth = width[currentphoto];
   document.images.photoshow.width = curWidth;
  }
  if (height[currentphoto] != curHeight) {
   curHeight = height[currentphoto];
   document.images.photoshow.height = curHeight;
  }
}

