/* gallery.js - manages a rolling image gallery

 * it is drawn into the element in the HTML with id named in the
   "gallery_id" variable below.

*/

var gallery_id = "gallery";
var interval = 5 // seconds
var images = [
	"images/photos/home_images/1stXV2010.jpg",
	"images/photos/home_images/away2.jpg",
	"images/photos/home_images/away6.jpg",
	"images/photos/home_images/bideford1.jpg",
	"images/photos/home_images/bideford2.jpg",
	"images/photos/home_images/bideford8.jpg",
	"images/photos/home_images/bideford9.jpg"
	]

var gallery_element;

function getFileName(path) {
	path = path.toString();

	if (path.match(/\//)) {
		var path_split = path.split(/\//);
	} else {
		var path_split = path.split(/\\/);
	}

	var last_indx = path_split.length - 1;
	var fname = path_split[last_indx];
	return fname;
}

function getNextImageIndex() {
	var indx = -1;
	var current_image = gallery_element.src;

	for (var i = 0; i < images.length; i++) {

		if (getFileName(current_image) == getFileName(images[i])) {
			indx = i + 1;

			if (indx >= images.length) {
				indx = 0;
			}
			return indx;
		}
	}
}


function updateImage(image_index) {
	gallery_element.src = images[image_index];
	setTimeout("updateImage(getNextImageIndex())", interval * 1000);
}

function startImageRoller() {
	gallery_element = document.getElementById(gallery_id);
	var indx = 0;
	updateImage(0);
}
		
	
