$(function() {
	$('.pagination a').live('click', function(event) {
		event.preventDefault();
		var index = $(this).html();
		tickerPos = index;
		loadStory(parseInt(index)-1);
	}); 
	loadStory(0);
});
var stories = [];
function loadStory(index) {
	$('#newsflash-story-bg').fadeOut('normal', function() {
		$('#newsflash-loading').show();
		$('#newsflash-story-bg').remove();
	}); 
	if(!stories[index]) {
		$.get('/neuigkeiten/ajax/home/?format=html&index=' + index, function(resp) {
			stories[index] = resp;
			$('#newsflash-loading').fadeOut();
			$('#newsflash').append(resp);
			$('#newsflash-story-bg').fadeIn('normal', function() {
				$('#newsflash-story-bg').show();
				$('#newsflash-loading').hide();
			});
		}); 
	} else {
		$('#newsflash-loading').fadeOut();
		$('#newsflash').append(stories[index]);
		$('#newsflash-story-bg').fadeIn('normal', function() {
			$('#newsflash-story-bg').show();
			$('#newsflash-loading').hide();
		});
	}
}
var tickerPos = 1;
function newsTicker() {
	if(tickerPos < $('.pagination li').length) {
		loadStory(tickerPos);
		tickerPos++;
	} else {
		tickerPos = 0;
	}
}
var newsTick = window.setInterval("newsTicker()", 7500);

