$(document).ready(function() {
	var current = 0; 
	var slides = ['slideshow-1.html', 'slideshow-2.html', 'slideshow-3.html'];

	function showSlide() {
		$('#slideshow').load(slides[current], null, function() {
			$('.slideshow-container').fadeIn();
		});
	}

	function changeSlide(change_to) {
		// TODO: add checking of index
		if (change_to != current) {
			current = change_to;
			showSlide();
		}
	}

	function nextSlide() {
		if (current >= slides.length -1) {
			current = 0;
		} else {
			current++
		}
		showSlide();
	}

	$('#slideshow-container-1').click(function() {
		changeSlide(0);	
	});

	$('#slideshow-container-2').click(function() {
		changeSlide(1);	
	});

	$('#slideshow-container-3').click(function() {
		changeSlide(2);
	});

	$('#next').click(function() {
		nextSlide();
	});


	setInterval(nextSlide, 7000);

	showSlide();
});

