

//This is to add an event listener to start the slideshow automatically on page load

function addEvent(obj, evType, fn){
 if (obj.addEventListener){
   obj.addEventListener(evType, fn, false);
   return true;
 } else if (obj.attachEvent){
   var r = obj.attachEvent("on"+evType, fn);
   return r;
 } else {
   return false;
 }
}

//declaring the arrays for the pictures and the captions

var Picture = [];
var Caption = [];

//the PHP bit to scan the image directory and populate the arrays created above

Picture[1]  = 'slideimages/Block.jpg'
Caption[1] = 'Block%20Paving%20%3Cspan%20class%3D%22alt%22%3E%26amp%3B%3C%2Fspan%3E%20Driveways'
Picture[2]  = 'slideimages/Classic wooden pergolas.jpg'
Caption[2] = 'Classic wooden pergolas'
Picture[3]  = 'slideimages/Decking.jpg'
Caption[3] = 'Decking%20%3Cspan%20class%3D%22alt%22%3E%26amp%3B%3C%2Fspan%3E%20Patios'
Picture[4]  = 'slideimages/Driveways.jpg'
Caption[4] = 'Driveway%20%3Cspan%20class%3D%22alt%22%3E%26amp%3B%3C%2Fspan%3E%20Gate'
Picture[5]  = 'slideimages/Fencing.jpg'
Caption[5] = 'All%20types%20of%20fencing'
Picture[6]  = 'slideimages/Patios.jpg'
Caption[6] = 'All%20types%20of%20patio%20layout'
Picture[7]  = 'slideimages/Pergolas.jpg'
Caption[7] = 'Pergolas%20in%20a%20range%20of%20materials'
Picture[8]  = 'slideimages/Walkway pergolas.jpg'
Caption[8] = 'Walkway pergolas'

//declaring some variables, working out the random timing between slides and generating a random slide

var pl = Picture.length-1;
var preR = 1;
var r = genRand(1);
var timer = Math.floor((6000-2000)*Math.random()) + 3000;
var t;

//this function and the one below change the images and set the timings

function runSlideShow() {
	setTimeout('doRunSlideShow()', timer);
}

function doRunSlideShow(){
document.getElementById("PictureBox").setAttribute('src', Picture[r])
document.getElementById('CaptionBox').innerHTML = unescape(Caption[r]);
preR = r;
r = genRand(preR);
t = setTimeout('runSlideShow()', timer);
}

//generates a random number to decide which slide gets shown next (not the same one as last time though)

function genRand(check) {
	var rand = Math.ceil(pl*Math.random());
	if (rand == check){
	genRand(check);
	}
	return rand;
}

//this kicks the whole thing off in the browser when the page has loaded

if (document.getElementById) {

addEvent(window, 'load', runSlideShow);


}