window.addEventListener?window.addEventListener("load",so_init,false):window.attachEvent("onload",so_init);

var d=document, slideshows = new Array(), zInterval = null, pause=false;

function so_init() {
	if(!d.getElementById || !d.createElement)return;

	var css = d.createElement("link");
	css.setAttribute("href","fjc_fade.css");
	css.setAttribute("rel","stylesheet");
	css.setAttribute("type","text/css");
	d.getElementsByTagName("head")[0].appendChild(css);

	var divs = d.getElementsByTagName("div");

	for(var i=0;i<divs.length;i++) {
		if(typeof divs[i].className != "undefined") {
			var classes = divs[i].className.split(" ");
			if(classes[0] == "fjc_slideshow") {
				var delay = classes[1].substring(1);
				slideshows[i] = new Array(divs[i],divs[i].getElementsByTagName("img"),0,delay);
				for(var j=1;j<slideshows[i][1].length;j++) slideshows[i][1][j].xOpacity = 0;
				slideshows[i][1][0].style.display = "block";
				slideshows[i][1][0].xOpacity = .99;
				setTimeout("so_xfade("+i+")",delay);
				divs[i].onmouseover = function(){this.setAttribute("mouseover","1")};
				divs[i].onmouseout = function(){this.setAttribute("mouseover","0")};
			}
		}
	}
}

function so_xfade(index) {
	current = slideshows[index][2];
	cOpacity = slideshows[index][1][current].xOpacity;
	nIndex = slideshows[index][1][current+1]?current+1:0;
	nOpacity = slideshows[index][1][nIndex].xOpacity;

	if(slideshows[index][0].getAttribute("mouseover") == 1) {
		setTimeout("so_xfade("+index+")",50);
		return false;
	}

	cOpacity-=.1;
	nOpacity+=.1;

	slideshows[index][1][nIndex].style.display = "block";
	slideshows[index][1][current].xOpacity = cOpacity;
	slideshows[index][1][nIndex].xOpacity = nOpacity;

	setOpacity(slideshows[index][1][current]);
	setOpacity(slideshows[index][1][nIndex]);

	if(cOpacity<=0) {
		slideshows[index][1][current].style.display = "none";
		slideshows[index][2] = nIndex;
		setTimeout("so_xfade("+index+")",slideshows[index][3]);
	} else {
		setTimeout("so_xfade("+index+")",50);
	}

	function setOpacity(obj) {
		if(obj.xOpacity>.99) {
			obj.xOpacity = .99;
			return;
		}
		obj.style.opacity = obj.xOpacity;
		obj.style.MozOpacity = obj.xOpacity;
		obj.style.filter = "alpha(opacity=" + (obj.xOpacity*100) + ")";
	}

}