jQuery(function(){
	jQuery('.newsticker').each(function(){
		// assign id's
		var item_id = 0;
		jQuery('.newsitem', this).hide().each(function(){
			jQuery(this).attr('item_id', item_id);
			item_id++;
		});
		
		var length = jQuery('.newsitem', this).length;
		nextItem(this, length-1, length);
	});
	
	function nextItem(ticker, currentId, length){
		nextId = (currentId+1)%length;
		jQuery('.newsitem[item_id='+currentId+']', ticker).fadeOut(500, function(){
			jQuery('.newsitem[item_id='+nextId+']', ticker).fadeIn(500);
			setTimeout(function(){nextItem(ticker, nextId, length)}, 3000);
		});
	}
});
