document.observe("dom:loaded", runOnDOMready);

// slideshow
var images = "";
var total_images = 0;
var current_image = 0;
var zIndex = 1;

function runOnDOMready(){
	images = $('slideshow').childElements();
	total_images = images.length;	
	setInterval("runSlideshow()", 6000);
}

function runSlideshow(){
	zIndex++;
	if(current_image == total_images - 1){
		next_image = 0;
	} else {
		next_image = current_image + 1;
	}
	
	images[next_image].style.zIndex = zIndex;
	images[next_image].style.opacity = 0;	
	images[next_image].fade({ from: 0, to: 1, duration: 1.5})	

	if(current_image == total_images - 1){
		current_image = 0;
	} else {
		current_image++;
	}	
	
	console.log(current_image);	
}