//on ready
jQuery(document).ready(function(){

//call a function after a certain delay
function beginTimeNews (time, functionName) {
	$.timer(time, function (timer) {
		functionName();
	  	timer.stop();
	});
}

n_timeInterval = 12000;
//load new news
function n_initTime () {
	beginTimeNews (n_timeInterval, loadNewNewsItem);
};


//delay first call of inittime to make it change with faktabox
$.timer(n_timeInterval/2, function (timer) {
	n_initTime ();
  	timer.stop();
});


//load next news item
function loadNewNewsItem () {
	//calc next id
	nextId = parseInt($('#newsContainer').attr('newsId'))+1;
	//call the mother ship and get the next news
	$.ajax({
				type: "POST",
				url: "modules/mod_news.php",
				data: "newsId="+nextId,
				success: function(html) {
					//alert (html);
					changeNewsItem (html);
				}
 	});
}

//fade out, replace, fadein
function changeNewsItem (html) {
	$('#newsWrapper').slideUp (1500, function () {
		newHtml = $(html+' > #newsContainer').html();
		newBg = $(html+' > #newsContainer').css ('background');
		$('#newsWrapper').html(newHtml);
		$('#newsWrapper').css ('background', newBg);
		$('#newsWrapper').slideDown (500, function () {
			$('#newsWrapper #newsContainer').biggerlink();
			n_initTime ();
		});
	});
}

//end on ready
});