$(document).ready(function() {
	// 0 = prev
	// 1 = next
    timer = setInterval( "slideSwitch(1)", 5000 );
	var animating = false;
});


// 0 = prev
// 1 = next
function slideSwitch(dir) {
	animating = true;
    var $active = $('#slideshow DIV.active');				//	Alle anderen Elemente innerhalb dieses DIVs dürfen daher keinesfalls wieder DIVs sein weil sie sonst als eigenständige Slides betrachtet werden
	var $activeText = $('#slideshow DIV.active .slideContent');

    if ( $active.length == 0 ) {
		$active = $('#slideshow DIV:last');
		$activeText = $('#slideshow DIV:last .slideContent');
	}

	if (dir == 1) {		// IF   THEN   ELSE
	    var $next = $active.next().length ? $active.next() : $('#slideshow DIV:first');
		var $nextText = $active.next().length ?  $('#slideshow DIV:not(.active) .slideContent') : $('#slideshow DIV:first .slideContent');		//slides all but the active one
	}
	else if (dir == 0) {
		var $next = $active.prev().length ? $active.prev() : $('#slideshow DIV:last');
		var $nextText = $active.prev().length ? $('#slideshow DIV:not(.active) .slideContent') : $('#slideshow DIV:last .slideContent');
	}

	$active.addClass('last-active');



	$nextText.animate({left: "+=200px"}, 0);
	$nextText.animate({left: "-=200px"}, 1000);

	
	
    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() { $active.removeClass('active last-active'); animating=false; } );	// Callback Function wird ausgeführt wenn animation beendet ist
	
	
	

	
	clearInterval(timer);
	timer = setInterval( "slideSwitch(1)", 5000 );
	
	$("#slideshow-previous").click(showPreviousSlide);
	$("#slideshow-next").click(showNextSlide);
}



function showPreviousSlide()
{
	if (!animating)
		slideSwitch(0);
}

function showNextSlide()
{
	if (!animating)
		slideSwitch(1);
}
