$(document).ready(function() {
	// process submenu
	$('#newsPanel li').hide();
	$('#newsPanel li:first').show().addClass('on');
	setInterval('loop()',5000);
	
	$('#client li').hide();
	$('#client li:first').attr("name", "currentClient").css("display","block");	
	
	setInterval('clientShow()',10000);
	
});

function loop() {
	var current = ($('#newsPanel li.on')? $('#newsPanel li.on') : $('newsPanel li:first')); // check if any 'li' has 'on' class, if not, grab the first 'li'
	var next = ((current.next().length)? current.next() : $('#newsPanel li:first')); // get next 'li', if it reached the end of the list, rotate it back to the first news
	//the animation
	current.fadeOut('slow', function() {
		$(this).removeClass('on');
		next.fadeIn('slow', function() {$(this).addClass('on');});
	});
}

function clientShow(){
	var firtItem = $('#client li:first');
	var currentClient = $("#client li[name='currentClient']"); 	
	var nextClient = ((currentClient.next().length) !=0 ? currentClient.next() : firtItem);
	//console.log(currentClient.next().length);
	currentClient.fadeOut('slow', function() {										   
		$(this).removeAttr("name");
		//$(this).attr("name","");
		//console.dir($(this));
		$(this).css("display","none");		
		nextClient.fadeIn('slow', function() {
			$(this).attr("name", "currentClient");	
			$(this).css("display","block");			
		});
	});
															  
}
