
var images = new Array(), zInterval = null, current=0, pause=false,interval=3000;
function init_slideshow() {
    if(el = document.getElementById("slideshow")) {
        images = el.getElementsByTagName("img");
        for(i=1;i<images.length;i++) images[i].target_opacity = 0;
        images[0].style.display = "block";
        images[0].target_opacity = .99;
        
        setTimeout(slide_fade,interval);
    }
}

function slide_fade() {
	current_opacity = images[current].target_opacity;
	next_image = images[current+1]?current+1:0;
	next_image_opacity = images[next_image].target_opacity;
	
	current_opacity-=.05; 
	next_image_opacity+=.05;
	
	images[next_image].style.display = "block";
	images[current].target_opacity = current_opacity;
	images[next_image].target_opacity = next_image_opacity;
	
	setOpacity(images[current]); 
	setOpacity(images[next_image]);
	
	if(current_opacity<=0) {
		images[current].style.display = "none";
		current = next_image;
		setTimeout(slide_fade,interval);
	} else {
		setTimeout(slide_fade,50);
	}
	
	function setOpacity(obj) {
		if(obj.target_opacity>.99) {
			obj.target_opacity = .99;
			return;
		}
		obj.style.opacity = obj.target_opacity;
		obj.style.MozOpacity = obj.target_opacity;
		obj.style.filter = "alpha(opacity=" + (obj.target_opacity*100) + ")";
	}
	
}

addLoadEvent(function() {
    if(document.getElementById("slideshow")){
        init_slideshow();
    }
});