// BEGIN CONFIGURING VALUES
var delay = 5500; // Set the delay between transitions
var tspeed = 0.5; // Set the transition speed
// END CONFIGURING VALUES
var start_frame = 0;
var end_frame = 0;
var current_frame = 0;
var prev_frame = 0;
var tm = null;
var lis = null;

function init_slideshow() {
	lis = $$('div.slidewrapper');
	for( i=0; i < lis.length; i++){
		if (i!=0) {
			lis[i].style.display = 'none';
		}
	}
	
	end_frame = lis.length -1;
	
	start_slideshow(start_frame+1);
	$('slideshowButtons').style.display = '';
}

function start_slideshow(start) {
	clearTimeout(tm);
	tm = setTimeout(fadeInOut(start, delay), delay);
}

function pause_slideshow() {
	clearTimeout(tm);
}

function continue_slideshow() {
	start_slideshow(prev_frame+1);
}

function fadeInOut(frame, delay, cont) {
	return (function() {
		Effect.Fade(lis[prev_frame], {duration: tspeed});
		if (frame > end_frame) frame = start_frame;
		lisAppear = lis[frame];
		setTimeout("Effect.Appear(lisAppear, {duration: tspeed});", 0);
		select_button(frame+1);
		if (cont != false) {
			tm = setTimeout(fadeInOut(frame+1, delay), delay);
		}
		prev_frame = frame;
	})
}

//Event.observe(window, 'load', init_slideshow, false);

function change_slide(num) {
	if (num-1 != prev_frame) {
		clearTimeout(tm);
		fadeInOut(num-1, delay, false).call();
	}
}

function select_button(num) {
	for (var i = 1; i <= lis.length; i++) {
		$('selectslide' + i).src = '/images/buttons/button_up.gif';
	}
	$('selectslide' + num).src = '/images/buttons/button_down.gif';
}