function slideShow(speedInMs) {

	//append a LI item to the UL list for displaying caption
	$('ul.slideshow').append('<li id="slideshow-caption" class="caption"><div class="slideshow-caption-container"><h1 id="slideshow-caption-headline"></h1><div id="slideshow-caption-description"></div></div><a id="slideshow-caption-readmore" class="button" href="#">Mehr lesen</a></li>');
	$('#slideshow-caption').animate({'bottom':'-1'}, 500);
	
	//Set the opacity of all images to 0
	$('ul.slideshow li:not(#slideshow-caption)').css({opacity: 0.0});
	$('#slideshow-caption-readmore').css({opacity: 0.0});
	
	//Get the first image and display it (set it to full opacity)
	$('ul.slideshow li:first').css({opacity: 1.0});
	
	//Get the caption of the first image from REL attribute and display it
	$('#slideshow-caption h1').html($('ul.slideshow li:first').find('img').attr('title'));
	$('#slideshow-caption-description').html($('ul.slideshow li:first div.hidden').html());
		
	//Display the caption
	$('#slideshow-caption').css({bottom:0});
	
	//Call the gallery function to run the slideshow	
	var timer = setInterval('slideItem()',speedInMs);
		
	//pause the slideshow on mouse over
	$('ul.slideshow').hover(
		function () {
			clearInterval(timer);
			var current = ($('ul.slideshow li.show')?  $('ul.slideshow li.show') : $('#ul.slideshow li:first'));
			$("#slideshow-caption-readmore").attr("href",current.find('a').attr('href'));			
			$("#slideshow-caption-readmore").css({'visibility':'visible'});
			$("#slideshow-caption-readmore").animate({opacity: 1}, 600);	
		}, 	
		function () {
			$("#slideshow-caption-readmore").animate({opacity: 0.0}, 600,function(){
				$("#slideshow-caption-readmore").attr("href","#");
				$("#slideshow-caption-readmore").css({'visibility':'hidden'});					
			});	
			timer = setInterval('slideItem()',speedInMs);			
		}
	);

	$('#news_liste a').hover(function(){
		$(this).find("span").attr('class','button_small_pressed');
	},
	function(){
		$(this).find("span").attr('class','button_small');
	});	
	
	$('#news_liste a').click(function(){
		clearInterval(timer);
		var current = ($('ul.slideshow li.show')?  $('ul.slideshow li.show') : $('#ul.slideshow li:first'));			
		var htmlId = "#slide_" + $(this).attr('id');
		slideItem(htmlId);
		timer = setInterval('slideItem()',speedInMs);
	});
}

function slideItem(htmlId){
	//if no IMGs have the show class, grab the first image
	var current = ($('ul.slideshow li.show')?  $('ul.slideshow li.show') : $('#ul.slideshow li:first'));
	if (!htmlId)
	{
		//Get next image, if it reached the end of the slideshow, rotate it back to the first image
		var next = ((current.next().length) ? ((current.next().attr('id') == 'slideshow-caption')? $('ul.slideshow li:first') :current.next()) : $('ul.slideshow li:first'));
	}
	else
	{
		//Nächste Objekt wurde übergeben
		var next = $(htmlId);
	}
	//Get next image caption
	var title = next.find('img').attr('title');	
	var desc = next.find('div').html();
	
	//Set the fade in effect for the next image, show class has higher z-index
	next.css({opacity: 0.0}).addClass('show').animate({opacity: 1.0}, 1000);
	
	//Hide the caption first, and then set and display the caption
	$('#slideshow-caption').animate({bottom:-70}, 500, function () {
			//Display the content
			$('#slideshow-caption h1#slideshow-caption-headline').html(title);
			$('#slideshow-caption div#slideshow-caption-description').html(desc);
			$('#slideshow-caption').animate({bottom:-1}, 800);	
	});
	//Hide the current image
	current.animate({opacity: 0.0}, 1000).removeClass('show');	
}

function toggleContent(){
	$('.inhalte').children('a.button').css({opacity: 0.2});
	$('.inhalte').hover(function(){
			$(this).children('a.button').animate({opacity: 1}, 500);
		},
		function(){
			$(this).children('a.button').animate({opacity: 0.2}, 500);
	});
	$('.inhalte').children('a.button').click(function(){
		if($(this).attr("href") == "#readmore")
		{
			$(this).parent().children('div').toggle();			
		}
		else
		{
			window.location.href = $(this).attr("href");
		}
	});	
	$('.inhalte').children('a.button').toggle(function(){
		$(this).find('img').attr("src","images/icons/button_icon_up.png");
		//alert($(this).find('img').attr("class") + " -- " + $(this).find('img').attr("src") + " rein ->>>");
	},
	function(){
		$(this).find('img').attr("src","images/icons/button_icon_down.png");
		//alert($(this).find('img').attr("class") + " -- " + "<<<- raus" + $(this).find('img').attr("src"));
	});		
	
	/*
	$('.inhalte').children('a.button').click(function(){
		if($(this).attr("href") == "#readmore")
		{
			$(this).toggle(function(){
				$(this).find('img').attr("src","images/icons/button_icon_up.png");
				//alert($(this).find('img').attr("class") + " -- " + $(this).find('img').attr("src") + " rein ->>>");
			},
			function(){
				$(this).find('img').attr("src","images/icons/button_icon_down.png");
				//alert($(this).find('img').attr("class") + " -- " + "<<<- raus" + $(this).find('img').attr("src"));
			});		
		}
	}); */
}

// main
$(document).ready(function() {		
	
	//News slideShow oben. param Wechselgeschwindigkeit in ms
	slideShow(5000);	
	toggleContent();

});