//Ajax-Suche

	function getXMLHttpRequest() {
		var httpReq = null;
		try {
			// Mozilla, Opera, Safari sowie Internet Explorer (ab v7)
			httpReq = new XMLHttpRequest();
		} catch(e) {
			try {
				// MS Internet Explorer (ab v6)
				httpReq = new ActiveXObject("Microsoft.XMLHTTP");
			} catch(e) {
				try {
					// MS Internet Explorer (ab v5)
					httpReq = new ActiveXObject("Msxml2.XMLHTTP");
				} catch(e) {
					httpReq = null;
				}
			}
		}

		return httpReq;
	}
	
	function sendPicRequest(url, handler, param) {
		req = getXMLHttpRequest();
		if (req) {
			req.onreadystatechange = handler;
			req.open("get", url + "&request=" + param, true);
			req.send(null);
		}
	}
	
//----------------------------------

	function timePic() {
		actPic();
		setTimeout('timePic()', 20000);
	}

	function startPic() {
		refreshPic();
		setTimeout('timePic()', 20000);
	}

	function actPic() {
			sendPicRequest("pic.php?time=" + new Date(),checkPic,"check");
	}
	
	function checkPic() {
		if (req.readyState == 4) {
			var newTime = req.responseText;
			var oldModPic = document.getElementById("modPic2");
			
			if (oldModPic.alt != newTime) {
				picOut(100);
				setTimeout("refreshPic()", 2000);
			}
			
		}
	}
	
	function refreshPic() {
		sendPicRequest("pic.php?time=" + new Date(),changePic,"pic");
	}
	
	function changePic() {
		if (req.readyState == 4) {
			var newPics = req.responseText.split(" ");
			var newModPic = newPics[0];
			var newShowPic = newPics[1];
			var newTimestamp = newPics[2] + " " + newPics[3];
			
			var oldModPic = document.getElementById("modPic2");
			var oldShowPic = document.getElementById("showPic2");
			
			oldModPic.src = "http://www.nsw-anime.de/images/streamstat/" + newModPic;
			oldShowPic.src = "http://www.nsw-anime.de/images/streamstat/" + newShowPic;
			oldModPic.alt = newTimestamp;
			
			setTimeout("picIn()", 1000);
			sendPicRequest("pic.php?time=" + new Date(),changeText,"text");
		}
	}
	
	function changeText() {
		if (req.readyState == 4) {
			var infoText = req.responseText.split("$");
			var infoNewShow = infoText[0];
			var infoNewTheme = infoText[1];
			var infoNewTime = infoText[2];
			
			var infoOldShow = document.getElementById("infoShow");
			var infoOldTheme = document.getElementById("infoTheme");
			var infoOldTime = document.getElementById("infoTime");
			
			infoOldShow.innerHTML = "<b>Sendung:</b><br />" + infoNewShow;
			infoOldTheme.innerHTML = "<b>Thema:</b><br />" + infoNewTheme + "&nbsp;";
			infoOldTime.innerHTML = "<b>l&auml;uft seit:</b><br />" + infoNewTime + " Uhr";
		}
	}
	
	function picOut(step) {
		var actModPic = document.getElementById("modPic2");
		var actShowPic = document.getElementById("showPic2");
		
		step = step;
		
		actModPic.style.opacity = step/100;
		actModPic.style.filter = "alpha(opacity=" + step + ")"; // IE

		actShowPic.style.opacity = step/100;
		actShowPic.style.filter = "alpha(opacity=" + step + ")"; // IE
		
		step = step - 1;
		
		if (step >= 0) {
			window.setTimeout(function () { picOut(step); }, 10);
		}
	}
	
	function picIn(step) {
		var actModPic = document.getElementById("modPic2");
		var actShowPic = document.getElementById("showPic2");
		
		step = step || 0;
		
		actModPic.style.opacity = step/100;
		actModPic.style.filter = "alpha(opacity:" + step + ")"; // IE

		actShowPic.style.opacity = step/100;
		actShowPic.style.filter = "alpha(opacity:" + step + ")"; // IE
		
		step = step + 1;
		
		if (step <= 100) {
			window.setTimeout(function () { picIn(step); }, 10);
		}
	}
	
	function textOut() {
		var actShowText = document.getElementById("showInfo");
		var step = actShowText.style.opacity;

		if (step > 0) {
					
			step = step * 100 - 4;
			
			actShowText.style.opacity = step/100;
			actShowText.style.filter = "alpha(opacity:" + step + ")"; // IE
			
			window.setTimeout("textOut()", 25);
		}
	}

	function textIn() {
		var actShowText = document.getElementById("showInfo");
		var step = actShowText.style.opacity || 0;

		if (step < 0.8) {
					
			step = step * 100 + 4;
			
			actShowText.style.opacity = step/100;
			actShowText.style.filter = "alpha(opacity:" + step + ")"; // IE
			
			window.setTimeout("textIn()", 25);
		}
	}