
function toggleSlider(el_id, clear) {
	if (clear) {
		window.clearTimeout(timeoutId);
		index = el_id;
	} else {
		index++;
		if (index == slideshow_length) {
			index = 0;
		}
	}
	for (var x = 0; x < slideshow_length; x++) {
		document.getElementById("slideshow_href_" + x).className = "item";
		document.getElementById("slideshow_href_image_" + x).style.display = "none";
		document.getElementById("slideshow_caption_" + x).style.display = "none";
	}
	var el = document.getElementById("slideshow_href_" + index);
	el.className = "item active";
	document.getElementById("slideshow_href_image_" + index).style.display = "";
	document.getElementById("slideshow_caption_" + index).style.display = "";
	fade(document.getElementById("slideshow_image_" + index), 25, 5);
}
var timeoutId = null;
var slideshow_length = null;
var index = 0;
function start() {
	toggleSlider(index, false);
}
function init(length) {
	slideshow_length = length;
	timeoutId = window.setInterval("start()", 5000);
}


// fade in / fade out function (event handler)
var opHigh = 100; // highest opacity level   
var opLow = 20;  // lowest opacity level (should be the same as initial opacity in the CSS)      
function fade(mi, opacity, step) {
	mi.style.opacity = opacity / 100;
	mi.style.filter = "alpha(opacity=" + opacity + ")";
	opacity = opacity + step;
	if (opLow <= opacity && opacity <= opHigh) {
		setTimeout(function () {
			fade(mi, opacity, step);
		}, 15);
	}
}

