// global variables
var arr_sliders = new Object();
var hdl_slideshow_timeout = null;
var MODULE_SLIDE_SHOW_ROTATION_TIMEOUT = 5000;

// increment slider one image
function NextImage() {

	if ((null == arr_sliders) ||
		(null == arr_sliders.images) ||
		(null == document.getElementById('module-slide-show-image')) ||
		(0 == arr_sliders.images.length))
	{
		return;
	}

	arr_sliders.current++;

	// check for overflow
	if (arr_sliders.images.length <= arr_sliders.current) {
		arr_sliders.current = 0;
	}

	// swap current image with new image
	document.getElementById('module-slide-show-image').src = arr_sliders.images[arr_sliders.current].src;

	return;
}

// decrement slider one image
function PreviousImage() {

	if ((null == arr_sliders) ||
		(null == arr_sliders.images) ||
		(null == document.getElementById('module-slide-show-image')) ||
		(0 == arr_sliders.images.length))
	{
		return;
	}

	arr_sliders.current--;

	// check for overflow
	if (0 > arr_sliders.current) {
		arr_sliders.current = arr_sliders.images.length - 1;
	}

	// swap current image with new image
	document.getElementById('module-slide-show-image').src = arr_sliders.images[arr_sliders.current].src;

	return;
}

// for building reference arrays of images
function GetImages() {

	if ((null != arr_sliders) &&
		(null != arr_sliders.images) &&
		(null != document.getElementById('module-slide-show-image')) &&
		(0 < arr_sliders.images.length))
	{
		document.getElementById('module-slide-show-image').src = arr_sliders.images[arr_sliders.current];
	}

	return;
}

function SlideShow() {

	if (hdl_slideshow_timeout) {
		clearTimeout(hdl_slideshow_timeout);
	}
	
	NextImage();

	hdl_slideshow_timeout = setTimeout(function() {
		SlideShow();
	}, MODULE_SLIDE_SHOW_ROTATION_TIMEOUT);

	return;
}

// stops the show on click and changes the button to "start"
function StopSlideShow() {

	if (hdl_slideshow_timeout) {
		clearTimeout(hdl_slideshow_timeout);
	}
	
		document.getElementById("slide-show-control-button").innerHTML= "PLAY";
	
	return;
}

// starts the show on play and changes the button to "stop"
function StartSlideShow() {

	if (hdl_slideshow_timeout) {
		clearTimeout(hdl_slideshow_timeout);
	}

	NextImage();

	hdl_slideshow_timeout = setTimeout(function() {
		SlideShow();
	}, MODULE_SLIDE_SHOW_ROTATION_TIMEOUT);

}
