var current = 0;

function nextImg() {
	current++;
	if (current >= unit_count) {
		current = 0;
	}
	prevImage = current - 1;
	if (prevImage < 0) {
		prevImage = unit_count - 1;
	} else if (prevImage > unit_count) {
		prevImage = 0;
	}
	document.getElementById("unit" + prevImage).style.display = "none";
	document.getElementById("unit" + current).style.display = "block";
	imgNoInfo();
}

function prevImg() {
	current--;
	if (current < 0) {
		current = unit_count - 1;
	}
	prevImage = current + 1;
	if (prevImage < 0) {
		prevImage = unit_count - 1;
	} else if (prevImage >= unit_count) {
		prevImage = 0;
	}
	document.getElementById("unit" + prevImage).style.display = "none";
	document.getElementById("unit" + current).style.display = "block";
	imgNoInfo();
}

var slideshowInterval;

function startSlideshow() {
	slideshowInfo("<a href='javascript:void()' onclick='stopSlideshow()' title='Slideshow running'>&raquo;</a>");
	slideshowInterval = setInterval("nextImg()", 5000);
}

function stopSlideshow() {
	slideshowInfo("<a href='javascript:void()' onclick='startSlideshow()' title='Slideshow stopped'>||</a>");
	clearInterval(slideshowInterval);
}

function toggleInfoText() {
	$('info-text').toggle();
	if ($('info-text').visible()) {
		stopSlideshow();
	} else {
		startSlideshow();
	}
}

function hideInfoText() {
	$('info-text').hide();
}

function slideshowInfo(message) {
	$('slideshow-info').innerHTML = message;
}

function imgNoInfo() {
	$('imgno-info').innerHTML = (current + 1) + " of " + unit_count;
}

Event.observe(window, 'load', function() { imgNoInfo() });