$(function() {
	dynamicNews('firstNewsContainer', 4000, 'first');
	dynamicNews('secondNewsContainer', 5000, 'middle');
	
	var Obj = new Partners('#partners', 'elem', 9, 700, 500);
});

function dynamicNews(container, timeInterval, firstElem, timeoutTime)
{
	var newsTotal = 0;
	var current = 0;
	$('#' + container).children().each(function() {
		$(this).hide();
		++newsTotal;
	});
	
	if (firstElem == 'middle')
		current = Math.floor(newsTotal / 2);
	 
	$('#' + container + ' div:eq(' + current++ + ')').addClass('active').show();
	
	if (newsTotal > 1) {		
		setInterval(function(){
			$('#' + container + ' .active').removeClass('active').fadeOut(500);
			
			setTimeout(function(){
				$('#' + container + ' div:eq(' + current++ + ')').addClass('active').fadeIn(500);
				if (current >= newsTotal)
					current = 0;
			}, 500);
			
		}, timeInterval);
	}
}
