

var nShows = 0;
var changeTime = 5000; /* Important: imgChangeTime > imgFadeOut */
var fadeIn = 1000;
if(navigator.appName=="Microsoft Internet Explorer"){ fadeIn /= 5;}



function nSlideShows() {
	for(var i = 0;; i++){
        var obj = document.getElementById("slideshow_" + i);
        if(obj==null) return i;
    }
}

function changeOpacity(opacity, id) {
    var obj = document.getElementById(id);
    obj.style.opacity = (opacity / 100);
    obj.style.filter = "Alpha(opacity="+opacity+")";
}

function init() {
	for(var show = 0; show < nShows; show++){
	
		var slideshow = document.getElementById("slideshow_" + show);
		slideshow.style.position = "relative";
		
		var pos = 0;
		var obj = document.getElementById("slide_" + show + "_" + pos);
		
		while(obj != null){					
			changeOpacity(0, "slide_" + show + "_" + pos);  
			obj.style.position = "absolute";
	        obj.style.left = "0px";
	        obj.style.top = "0px"; 
	        obj.style.display = "block";
	        obj.style.zIndex = "0";
						
			pos++;
			obj = document.getElementById("slide_" + show + "_" + pos); 		        
		}

    }
}

function run(id, slide) {
	
	var children = document.getElementById(id).childNodes;
	
	var prev = slide-1;
	if(prev == -1) prev = children.length-1;
	
	/* set zIndex */
	var obj = children[slide];
	obj.style.zIndex = "1";
	obj = children[prev];
	obj.style.zIndex = "0";
	
	/* Fade In new slide */
	fade(children[slide]);
	
	if(children.length == 1) return;
	
	/* disable old slide */
	setTimeout("disable('"+ children[prev].id +"')",fadeIn);
	
	
	/* redo */
	slide++;
	if(slide == children.length) slide = 0;
	
	
	setTimeout("run('" + id + "','" + slide + "')", changeTime);

}

function disable(id) {
	var obj = document.getElementById(id);
	changeOpacity(0, id);
}


function fade(obj){
	var speed = Math.round(fadeIn/100);
	var timer = 0;
				
	for(i = 0; i <= 100; i++) {
		setTimeout("changeOpacity(" + i + ",'" + obj.id + "')",(timer * speed));
		timer++;
	}
}




window.onload = function () {
	nShows = nSlideShows();
	init();
	for(var i = 0; i < nShows; i++){
		setTimeout("run('slideshow_" + i + "','0')",i * (fadeIn/nShows));
	}
}






