// set the starting image.
var i = 0;		
var play=null;
// The array of div names which will hold the images.
var image_slide = null;
// The number of images in the array.
var NumOfImages = null;
// The time to wait before moving to the next image. Set to 3 seconds by default.
var wait = 6000;
// The Fade Function
function SwapImage(x,y) {
Effect.Appear(image_slide[x], { duration: 3.0 });
Effect.Fade(image_slide[y], { duration: 3.0 });
}
// the onload event handler that starts the fading.
function StartSlideShow() {
	image_slide = document.getElementsByClassName("fadebox");
	lesImages = $$('.fadebox img');
	var cpt = 0;
	var maxHeight = 0;
	var leWidth = 0;
	while(cpt<lesImages.length) {
		if(lesImages[cpt].height > maxHeight){
			maxHeight = lesImages[cpt].height;
			leWidth = lesImages[cpt].width;
		}
		cpt++;
	}
	$('image-container').style.height = Math.round((maxHeight*327/leWidth))+'px';
	NumOfImages=image_slide.length;
	var no=0;
	play = setInterval('Play()',wait);
}
function Play() {
	var imageShow, imageHide;
	imageShow = i+1;
	imageHide = i;
	if (imageShow == NumOfImages) {
		SwapImage(0,imageHide);	
		i = 0;					
	} else {
		SwapImage(imageShow,imageHide);			
		i++;
	}
}

Event.observe(window,'load',StartSlideShow);