function fadeIn(step) {
	var div = document.getElementById('slideshow');

	step = step || 0;

	div.style.opacity = step/100;
	div.style.filter='progid:DXImageTransform.Microsoft.Alpha(Opacity=' + step + ')'; // IE 8
	//div.style.filter = "alpha(opacity=" + step + ")"; // IE

	step = step + 2;

	if (step <= 100) {
		window.setTimeout(function () { fadeIn(step); }, 50);
	}
}

function fadeOut(step) {
	var div = document.getElementById('slideshow');

	step = step || 100;

	div.style.opacity = step/100;
	div.style.filter='progid:DXImageTransform.Microsoft.Alpha(Opacity=' + step + ')'; // IE 8
	//div.style.filter = "alpha(opacity=" + step + ")"; // IE
	

	step = step - 2;

	if (step > 0) {
		window.setTimeout(function () { fadeOut(step); }, 50);
	}
}

var intervalID = 0;
var currentID = 0;

function toggleSlideshow() {
	if(document.getElementById('toggleSlideshow').innerHTML == 'Slideshow anhalten') {
		clearInterval(intervalID);
		document.getElementById('toggleSlideshow').innerHTML = 'Slideshow fortführen';
	} else if(document.getElementById('toggleSlideshow').innerHTML == 'Stop Slideshow') {
		clearInterval(intervalID);
		document.getElementById('toggleSlideshow').innerHTML = 'Continue Slideshow';	
	} else if(document.getElementById('toggleSlideshow').innerHTML == 'Continue Slideshow') {
		loadNewContent();
		intervalID = setInterval("loadNewContent()", 7000);
		document.getElementById('toggleSlideshow').innerHTML = 'Stop Slideshow';		
	} else if(document.getElementById('toggleSlideshow').innerHTML == 'Slideshow fortführen') {
		loadNewContent();
		intervalID = setInterval("loadNewContent()", 7000);
		document.getElementById('toggleSlideshow').innerHTML = 'Slideshow anhalten';		
	}
}
function slideshow() {
	document.getElementById('slideshow').style.background = '#fff';
	document.getElementById('slideshow').style.zoom = 1;
	loadNewContent();
	intervalID = setInterval("loadNewContent()", 7000);
}
function loadNewContent() {
	var id = parseInt(Math.random() * urlcount);
	while(id == currentID) {
		id = parseInt(Math.random() * urlcount);
	}
	currentID = id;
	var xmlhttp;

  try
  {
    // Firefox, Opera 8.0+, Safari

    xmlhttp=new XMLHttpRequest();
  }
  catch (e)
  {
    // Internet Explorer

    try
    {
      xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (e)
    {
      try
      {
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
      catch (e)
      {
        alert("Your browser does not support AJAX!\nThe site's content cannot be accessed by your browser.\n\nI recommend downloading:\n - Internet Explorer 7\n - Mozilla Firefox 2\n - Opera");
        return false;
      }
    }
  }
	xmlhttp.open("GET", root + "slideshow.php?id=" + id,true);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			fadeOut();
			window.setTimeout(function () {
				document.getElementById('slideshow').innerHTML = xmlhttp.responseText;
				fadeIn();}, 50*51);
		}
	}
	xmlhttp.send(null);

}
