/**
 * flk.slideshow.js
 */


function slideSwitch(switchSpeed) {
    var $active = $('#slideShow img.active');

   // if ( $active.length == 0 ) $active = $('#slideShow img:last');

    var $next =  $active.next('img').length ? $active.next('img') : $('#slideShow img:first');
	
	
	//$active.css("position","absolute");
	//$next.css("position","relative");

    $active.addClass('last-active').fadeOut(switchSpeed);
	
	//$active.css("position","absolute");
	
	$next.addClass('active').fadeIn(switchSpeed);
	
	$active.removeClass('active last-active');

}

$(document).ready(function() {
	$('#slideShow img').css("position","absolute");
	$('#slideShow img:gt(0)').hide();
	//$('#slideShow').css('height',$('#slideShow img:first').height()); not necessary
	//$('#slideShow').css('overflow','hidden'); not necessary
	
	$('#slideShow img:first').css("display", "block").addClass('active');
	
	interval = "";

	


	// Die Next Function haben wir in der eigentlichen Funktion ja schon drin, 
	// also rufen wir die Funktion auf und stoppen das Intervall, damit die Slideshow nicht weiterlaeuft
	$(".next").click(function() {
		clearInterval(interval);
		slideSwitch(1000);
	});

	//Nun die Zurueck-Funktion
	$(".prev").click(function() {
		clearInterval(interval);
		var $active = $('#slideShow img.active');

		if ( $active.length == 0 ) $active = $('#slideShow img:first');

		var $next =  $active.prev('img').length ? $active.prev('img')
	       : $('#slideShow img:last');
		
		$active.addClass('last-active').fadeOut(3000);

		$next.addClass('active').fadeIn(2000);
		
		
		$active.removeClass('active last-active');
	});

	interval = setInterval ( "slideSwitch(1000)", 8000);
	
	
});

$(window).resize(function() {
    $('#slideShow').css('height',$('img.active:visible').height());
});
