$(document).ready(function() {
	var cnt = 0;
	var keys = new Array();
	var index = 0;
	$('#wieiswieblock').find('.wieiswie_carousel').each(function(){
		$(this).hide(); //hide
		keys[cnt] = $(this).attr('id'); //and put in array
		cnt++;
	});
	
	var max = keys.length - 1;	
	if(max != 0){
		startCarousel();	
	} else {
		$('#wieiswieblock #' + keys[0]).show();
	}
	
	$('a.wieiswie_next').click(function(){
		moveNext();
		//$('a#wieiswie_next').bind("click")
		return false;
	});
	
	/*function nextButton(){
		
	}*/
	
	$('a.wieiswie_prev').click(function(){
		movePrev();
		return false;
	});
	
	function moveNext(){
		//show current one
		//$('#wieiswieblock #' + keys[index]).fadeIn("slow");		
		$('#wieiswieblock #' + keys[index]).show();

		if(index == 0) var last = max;
		else var last = index - 1; 

		if(index < max ) index++;
		else index = 0;				

		//$('#wieiswieblock #'+keys[last]).fadeOut("slow");	
		//if(last != index){
			$('#wieiswieblock #'+keys[last]).hide();	
		//}		
	}
	
	function movePrev(){
		//show current one
		//$('#wieiswieblock #' + keys[index]).fadeIn("slow");		
		$('#wieiswieblock #' + keys[index]).show();

		if(index == 0) var last = max;
		else var last = index - 1; 

		if(index > 0 ) index--;
		else index = max;				

		//$('#wieiswieblock #'+keys[last]).fadeOut("slow");	
		//if(last != index){
			$('#wieiswieblock #'+keys[last]).hide();	
		//}			
	}
	
	function startCarousel(){
		moveNext();		
		
	 	x = setTimeout(function() { startCarousel() }, 10000);				
	}


});
