// JavaScript Document

var slideshowLooper;
 
function linkSlide(node) {
	var images = node.getElementsByTagName('img');
	for(var n = 0; n < images.length; ++n) {
		if(images[n].className.indexOf('backButton') > -1) {
			images[n].onclick = slideBack;
		}
		else if(images[n].className.indexOf('pauseButton') > -1) {
			images[n].onclick = function() { clearInterval(slideshowLooper); };
		}
		else if(images[n].className.indexOf('forwardButton') > -1) {
			images[n].onclick = slideForward;
		}
	}
}
 
function slideBack() {
	var slides = document.getElementById('slideshow_inner').childNodes;
	var previousIndex = null;
	for(var n = 0; n < slides.length; ++n) {
		var current = slides[n];
		if(!current.className || current.className.indexOf('slide') < 0) {
			continue;
		}
 
		if(current.className.indexOf('active') > -1) {
			current.className = current.className.replace(/ ?active/g, '');
			if(previousIndex != null) {
				break;
			}
		}
 
		previousIndex =  n;
	}
	slides[previousIndex].className += ' active';
}
function slideForward() {
	var slides = document.getElementById('slideshow_inner').childNodes;
	var activateNext = false;
	var firstSlideIndex = null;
	for(var n = 0; n < slides.length; ++n) {
		var current = slides[n];
		if(!current.className || current.className.indexOf('slide') < 0) {
			continue;
		}
		if(firstSlideIndex == null) {
			firstSlideIndex = n;
		}
 
		if(activateNext) {
			current.className += ' active';
			activateNext = false;
		}
		else if(current.className.indexOf('active') > -1) {
			current.className = current.className.replace(/ ?active/g, '');
			activateNext = true;
		}
	}
	if(activateNext) {
		slides[firstSlideIndex].className += ' active';
	}
}
 
function slideshowLoop() {
	slideshowLooper = window.setInterval(slideForward, 1600);
}
 
function rgSlideshow() {
	var slides = document.getElementById('slideshow_inner').childNodes;
	for(var n = 0; n < slides.length; ++n) {
		if(slides[n].className && slides[n].className.indexOf('slide') > -1) {
			linkSlide(slides[n]);
		}
	}
	slideshowLoop();
} 


var slideshowOldOnload = window.onload;

window.onload = function() {
	
if(slideshowOldOnload) {
		slideshowOldOnload();
	}
	rgSlideshow();
}

