
var teaserCounter;
var t;
	
var timeCounter;

$(document).ready(function(){
	
	teaserCounter = 0;
	t = 0;
	timeCounter = 0;
	
	$('.home-news-teaser .layout_latest').each(function(){
		
		teaserCounter++;
		
	});

	showNews();
	
	$('#next-news').click(function(){
		
		nextImage();
		
	});
	
	$('#previous-news').click(function(){
		
		t--;
		
		if (t < 0){
			t = t + teaserCounter;
		}
		
		showNews();
		
	});	
	
	setInterval ( "everySecond()", 1000 );

});

function everySecond(){
	timeCounter++;
	if (timeCounter > 10){
		nextImage();
	}
}

function nextImage(){
	
	timeCounter = 0;
	
	t++;
	
	if (t >= teaserCounter){
		t = t - teaserCounter;
	}
	
	showNews();
}

function showNews(){

	
	$('.home-news-teaser .layout_latest').each(function(i){
		
		if (i == t){
			$(this).fadeIn(500);
		}else{
			$(this).fadeOut(500);
		}
		
		
	});
	
}

