var xmlhttparticle = null;
var d = document;
var zInterval = null;
var pause = false;
var playele = null;
var uniqs = new Array();
var alltypes = new Array();

var debugcounter = 0;

var configuration = new Array();

function setdebugcounter()
{
	debugcounter++;
	document.getElementById('debugcounter').innerHTML = debugcounter;
	window.setTimeout('setdebugcounter()', 1000);
}

function so_init()
{
	if (!document.getElementById || !document.createElement) 
	{
		return;
	}
	
	// DON'T FORGET TO GRAB THIS FILE AND PLACE IT ON YOUR SERVER IN THE SAME DIRECTORY AS THE JAVASCRIPT!
	// http://slayeroffice.com/code/imageCrossFade/xfade2.css
	css = document.createElement("link");
	css.setAttribute("href","xfade2_o.css");
	css.setAttribute("rel","stylesheet");
	css.setAttribute("type","text/css");
	document.getElementsByTagName("head")[0].appendChild(css);
	
	var tmpuniqs = new Date().getMilliseconds();
	
	// Fades konfigurieren
	for (var i = 0; i < alltypes.length; i++) 
	{
		type = alltypes[i];
		uniqs[type] = tmpuniqs;
		configuration[type]['current'] = 0;
		configuration[type]['imgs'] = new Array();
		configuration[type]['imgs'] = document.getElementById('fade' + type + 'container').getElementsByTagName('DIV');
		for (var n = 1; n < configuration[type]['imgs'].length; n++)
		{
			configuration[type]['imgs'][n].xOpacity = 0;
		}
		configuration[type]['imgs'][0].style.display = "block";
		configuration[type]['imgs'][0].xOpacity = .99;
	}
	
	// Befehl zum Ausfuehren absetzen
	for (var i = 0; i < alltypes.length; i++) 
	{
		type = alltypes[i];
		document.getElementById('debugcounterlist').innerHTML += 'INIT:' + type + '; ' + debugcounter + '<br>';
		window.setTimeout('so_xfade(' + type + ', ' + uniqs[type] + ')', configuration[type]['start']);		// Dauer bis zum 1. Ueberblendeffekt -->start
	}
}

function so_xfade(type, uniq)
{
	if (uniqs[type] != uniq)
	{
		alert('hier');
		return;
	}
	
	cOpacity = configuration[type]['imgs'][configuration[type]['current']].xOpacity;
	if (configuration[type]['imgs'][configuration[type]['current'] + 1])
	{
		nIndex = configuration[type]['current'] + 1;
	}
	else
	{
		nIndex = 0;
	}
	nOpacity = configuration[type]['imgs'][nIndex].xOpacity;
	
	cOpacity -= .05;	// Ueberblenddauer
	nOpacity += .05;	// Ueberblenddauer
	
	configuration[type]['imgs'][nIndex].style.display = "block";
	configuration[type]['imgs'][configuration[type]['current']].xOpacity = cOpacity;
	configuration[type]['imgs'][nIndex].xOpacity = nOpacity;
	
	setOpacity(configuration[type]['imgs'][configuration[type]['current']]); 
	setOpacity(configuration[type]['imgs'][nIndex]);
	
	if(cOpacity<=0)
	{
		configuration[type]['imgs'][configuration[type]['current']].style.display = "none";
		configuration[type]['current'] = nIndex;
		window.setTimeout('so_xfade(' + type + ', ' + uniqs[type] + ')', configuration[type]['dauer']);		// Dauer bis zum naechsten Ueberblendeffekt
		document.getElementById('debugcounterlist').innerHTML += type + ':' + debugcounter + '<br>';
	}
	else
	{
		window.setTimeout('so_xfade(' + type + ', ' + uniqs[type] + ')', configuration[type]['ueberblenddauer']);
	}
	
	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) + ")";
	}
}
