/*****

Image Cross Fade Redux
Version 1.0
Last revision: 02.15.2006
steve@slayeroffice.com

Please leave this notice intact. 

Rewrite of old code found here: http://slayeroffice.com/code/imageCrossFade/index.html


*****/


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

var d=document, imgs = new Array(), zInterval = null, current=0, pause=false;

var play
var fade_time = 0.05;
var show_time = 3500;
var fading = "no";

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

	imgs = d.getElementById("divContainer").getElementsByTagName("img");
	for(i=1;i<imgs.length;i++) imgs[i].xOpacity = 0;
	imgs[0].style.display = "block";
	imgs[0].xOpacity = .99;
	play = window.setTimeout(so_xfade,show_time);
	d.getElementById("preloader").style.display = "none";
	document.getElementById('butt_play').src = "http://www.kuenz.at/2010/images/icons/pause.gif";
	document.getElementById('control').style.visibility = "visible";
	current = 0;
}

function so_xfade() {
	fading = "yes";
	cOpacity = imgs[current].xOpacity;
	nIndex = imgs[current+1]?current+1:0;

	nOpacity = imgs[nIndex].xOpacity;
	
	cOpacity-=fade_time; 
	nOpacity+=fade_time;
	
	imgs[nIndex].style.display = "block";
	imgs[current].xOpacity = cOpacity;
	imgs[nIndex].xOpacity = nOpacity;
	
	setOpacity(imgs[current]); 
	setOpacity(imgs[nIndex]);
	
	if(cOpacity<=0) {
		document.getElementById("img_descr").innerHTML = bildtext[nIndex];
		document.getElementById("aktuelles_bild").innerHTML = nIndex + 1;
		imgs[current].style.display = "none";
		current = nIndex;
		fading = "no";
		play = window.setTimeout(so_xfade,show_time);
	} else {
		play = window.setTimeout(so_xfade,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) + ")";
}


function so_next(a) {
if (fading == "no"){
		
	cOpacity = imgs[current].xOpacity;

	if(a==1){
		nIndex = imgs[current+1]?current+1:0;
	}else if(a == -1){
		nIndex = current - 1;
		if(nIndex<0){nIndex=imgs.length-1;}
	}else{
		nIndex = a;
	}
	document.getElementById("butt_play").src = "http://www.kuenz.at/2010/images/icons/play.gif";
	document.getElementById("img_descr").innerHTML = bildtext[nIndex];
	document.getElementById("aktuelles_bild").innerHTML = nIndex + 1;

	nOpacity = imgs[nIndex].xOpacity;
	
	cOpacity-=fade_time; 
	nOpacity+=fade_time;
	
	imgs[nIndex].style.display = "block";
	imgs[current].xOpacity = cOpacity;
	imgs[nIndex].xOpacity = nOpacity;
	
	setOpacity(imgs[current]); 
	setOpacity(imgs[nIndex]);
	
	if(cOpacity<=0) {
		imgs[current].style.display = "none";
		current = nIndex;
		fading = "no";
	} else {
		play = window.setTimeout("so_next(" + a + ")",50);
	}
}else{
		play = window.setTimeout(so_xfade,50);
}
}
function so_play() {
if (fading == "no"){
	if(document.getElementById ('butt_play').src == "http://www.kuenz.at/2010/images/icons/play.gif"){
		document.getElementById ('butt_play').src = "http://www.kuenz.at/2010/images/icons/pause.gif";
		for(i=1;i<imgs.length;i++) imgs[i].xOpacity = 0;
		imgs[current].style.display = "block";
		imgs[current].xOpacity = .99;
		play = window.setTimeout(so_xfade,10);
	} else {
		document.getElementById ('butt_play').src = "http://www.kuenz.at/2010/images/icons/play.gif";
		window.clearTimeout(play);
	}
}
}
function click_picture(){
	if(document.getElementById ('butt_play').src == "http://www.kuenz.at/2010/images/icons/pause.gif"){
		so_play();
	}else{
		window.clearTimeout(play);
		so_next(1);
	}
}
