// JavaScript Document


var animationImages = [
		['set1img1.jpg', 'set1img2.jpg', 'set1img3.jpg'],
		['set2img1.jpg', 'set2img2.jpg', 'set2img3.jpg'],
		['set3img1.jpg', 'set3img2.jpg', 'set3img3.jpg']
		];

var setDelay = 3000;
var imageDelay = 800;
var transitionSpeed = 2.0;

var animationSetAt = 1;
var animationSetCount = animationImages.length;

var image1Top, image1Bottom;
var image2Top, image2Bottom;
var image3Top, image3Bottom;

function nextImages() {
	var e;
	e = image1Top; image1Top = image1Bottom; image1Bottom = e;
	e = image2Top; image2Top = image2Bottom; image2Bottom = e;
	e = image3Top; image3Top = image3Bottom; image3Bottom = e;

	image1Bottom.src = 'images/slideshow/' + animationImages[animationSetAt][0];
	image2Bottom.src = 'images/slideshow/' + animationImages[animationSetAt][1];
	image3Bottom.src = 'images/slideshow/' + animationImages[animationSetAt][2];

  setTimeout(nextSet, setDelay);
}

function fadeImage3() {
	Effect.Fade(image3Top, {duration: transitionSpeed });
	Effect.Appear(image3Bottom, {duration: transitionSpeed, afterFinish: waitForImage2 });
}



function waitForImage3() {
	setTimeout(fadeImage3, imageDelay);
}


function fadeImage2() {
	Effect.Fade(image2Top, {duration: transitionSpeed });
	Effect.Appear(image2Bottom, {duration: transitionSpeed, afterFinish: nextImages });
	

}



function waitForImage2() {
	setTimeout(fadeImage2, imageDelay);
}


function nextSet() {
	
//	new Effect.Opacity('animation1', {duration: transitionSpeed, from: 1.0, to: finalOpacity, afterFinish: showImage1} );	

	animationSetAt ++;
	if(animationSetAt >= animationSetCount) animationSetAt = 0;

	Effect.Fade(image1Top, {duration: transitionSpeed });
	Effect.Appear(image1Bottom, {duration: transitionSpeed, afterFinish: waitForImage3 });

}

Event.observe(window, 'load', function() {
	image1Top = $('animation1a');
	image1Bottom = $('animation1b');																			 
	image2Top = $('animation2a');
	image2Bottom = $('animation2b');																			 
	image3Top = $('animation3a');
	image3Bottom = $('animation3b');		

	image1Bottom.src = 'images/slideshow/' + animationImages[animationSetAt][0];
	image2Bottom.src = 'images/slideshow/' + animationImages[animationSetAt][1];
	image3Bottom.src = 'images/slideshow/' + animationImages[animationSetAt][2];
		
  setTimeout(nextSet, setDelay);
});