// Variables for image galleries
var currentImageIndex = 0;
var aImages = new Array();
var slideshow_delay = '5'; // in seconds
var the_timeout;

// -------------- Gallery Functions ------------- //
function startSlideshow(i){
	var oImg = document.getElementById('img_slideshow');
	var oCaption = document.getElementById('img_caption');

	document.getElementById('thumbnails').style.display = 'none';
	document.getElementById('slideshow').style.display = '';
	currentImageIndex = i;
	oImg.src = CFV_imgpath + 'galleries/' + aImages[currentImageIndex][0];
	oImg.altText = aImages[currentImageIndex][1];
	oCaption.innerText = aImages[currentImageIndex][2];
	togglePlay(false);
	the_timeout = setTimeout('showNextImage();', (slideshow_delay * 1000));
}

function showNextImage(bPause){
	var oImg = document.getElementById('img_slideshow');
	var oCaption = document.getElementById('img_caption');
	currentImageIndex++;
	if (currentImageIndex > (aImages.length-1)){
		currentImageIndex = 0;
	}

	oImg.src = CFV_imgpath + 'galleries/' + aImages[currentImageIndex][0];
	oImg.altText = aImages[currentImageIndex][1];
	oCaption.innerText = aImages[currentImageIndex][2];
	togglePlay(bPause);
	if (!bPause){
		the_timeout = setTimeout('showNextImage();', (slideshow_delay * 1000));
	}else{
		slideshow_pause();
	}
}

function showPrevImage(bPause){
	var oImg = document.getElementById('img_slideshow');
	var oCaption = document.getElementById('img_caption');
	currentImageIndex--;
	if (currentImageIndex < 0){
		currentImageIndex = (aImages.length-1);
	}

	oImg.src = CFV_imgpath + 'galleries/' + aImages[currentImageIndex][0];
	oImg.altText = aImages[currentImageIndex][1];
	oCaption.innerText = aImages[currentImageIndex][2];
	togglePlay(bPause);
	if (!bPause){
		the_timeout = setTimeout('showPrevImage();', (slideshow_delay * 1000));
	}else{
		slideshow_pause();
	}
}

function togglePlay(bShowPlay){
	document.getElementById('bPlay').style.display = (bShowPlay)?'':'none';
	document.getElementById('bPause').style.display = (bShowPlay)?'none':'';
}

function slideshow_pause(){
	togglePlay(true);
	clearTimeout(the_timeout);
}

function slideshow_forward(){
	clearTimeout(the_timeout);
	showNextImage(true);
}

function slideshow_back(){
	clearTimeout(the_timeout);
	showPrevImage(true);
}