var current = 0;
var createSlideShowId;
var delay = 8500;
var pause = false;
var imgpause = false;

function linkClicked(n, manual) {
	new Effect.Fade('featuredimage'+current, { duration: 0.8, queue: { position: 'end', scope: 'imgq' } });
	new Effect.Appear('featuredimage'+n,     { duration: 0.8, queue: { position: 'end', scope: 'imgq' } });
	
	//new Effect.Appear('featuredtextwhite',   { duration: 0.8, queue: { position: 'end', scope: 'txtq' } });
	new Effect.Fade('featuredtext'+current,  { duration: 0.8, queue: { position: 'end', scope: 'txtq' } });
	new Effect.Appear('featuredtext'+n,      { duration: 0.8, queue: { position: 'end', scope: 'txtq' } });
	//new Effect.Fade('featuredtextwhite',     { duration: 0.8, queue: { position: 'end', scope: 'txtq' } });

	current = n;
}

function initSlideshow() {
	if (max < 1) return;
	
	// start the slideshow
	createSlideShowId = setInterval(createSlideShow, delay);
}

function createSlideShow() {
	var next = parseInt(current) + 1;
	if (next > max) next = 0;
	linkClicked(next);
}

function backClicked() {
	if (current == 0) return;
	
	var next = parseInt(current) - 1;
	linkClicked($('featuredlink'+next), true);
}

function forwardClicked() {
	if (current == max) return;
	
	var next = parseInt(current) + 1;
	linkClicked($('featuredlink'+next), true);
}

function pauseClicked(a) {
	pause = !pause;
	a.innerHTML = pause ? 'play' : 'pause';
}

function imageOver() {
	if (pause) return;
	
	imgpause = true;
	$('pauselink').innerHTML = 'paused...';
}

function imageOut() {
	if (!imgpause) return;
	
	imgpause = pause = false;
	$('pauselink').innerHTML = 'pause';
}

window.onload = initSlideshow;

