var currentImage;
var ss_interval;
var ss_running = false;

function GalleryLink(photo) {
	if(!SetGalleryPhoto(photo))
		document.location.href = "gallery.php?photo" + photo;
}

function MyGetElem(name) {
	var myElem;
	if(document.getElementById)
		myElem = document.getElementById(name);
	else if(document.all)
		myElem = document.all[name];
	else if(document.layers)
		myElem = document.layers[name];
	else
		return false;
	return myElem;
}

function SetGalleryPhoto(photo) {
	var phElem;
	if(photo == currentImage)
		return true;
	phElem = MyGetElem('galImage');
	//phElem.src = 'images/equestrian_' + photo + '.jpg';
	crossfade(phElem,'images/equestrian_' + photo + '.jpg',1.5,'');
	SetCurrentPhoto(photo);
	return true;
}

function SetCurrentPhoto(photo) {
	currentImage = photo;
}

function PreloadGalPhotos() {
	var phList = new Array(8);
	
	for(var i=1; i <= 8; i++) {
		phList[i] = new Image();
		phList[i].src = 'images/equestrian_' + i + '.jpg';
	}
}

function GalleryButton(dir) {
	if( ( dir == 'forward') && (currentImage < 8) )
		SetGalleryPhoto(currentImage + 1);
	else if( (dir == 'back') && (currentImage > 1) )
		SetGalleryPhoto(currentImage - 1);
}

function NextImage() {
	var nextPhoto;
	if(currentImage == 8)
		nextPhoto = 0;
	else
		nextPhoto = currentImage + 1;
	SetGalleryPhoto(nextPhoto);
}

function ToggleSlideShow() {
	var tLink = MyGetElem('toggle_link');
	if(!ss_running) {
		ss_interval = setInterval(NextImage,3000);
		ss_running = true;
		tLink.innerHTML = 'Click here to stop slideshow';
	} else {
		clearInterval(ss_interval);
		ss_running = false;
		tLink.innerHTML = 'Click here to view slideshow';
	}
}