var currentLI = 0;
var lengthLI = 0;

var currentDiv = 0;
var rightSideLength = 0;

var currentNews = 0;

function autoPlay(){
	currentLI++;
	if(currentLI > lengthLI) { currentLI = 1; }
	
	var currTab = $('#countrytabs li:nth-child('+currentLI+')').attr('id');
	$('#countrytabs li>a').each(function(){
			$(this).removeClass('selected');
		});
	$('#'+currTab+' >a').addClass('selected');
	
	var currFeatProj = '#'+currTab+'_div';
	$('.content-inner>div').hide();
	$(currFeatProj).fadeIn(1900);
	aut = setTimeout("autoPlay()", 8500);
}

function autoPlayRight(){
	currentDiv++;
	if(currentDiv > rightSideLength) { currentDiv = 1; }
	

	var currRightDiv = '#sidebar_'+currentDiv+'_div';
	$('.sidebar-inner>div').hide();
	$(currRightDiv).fadeIn(1900);
	aut = setTimeout("autoPlayRight()", 8500);
}

function autoPlayNews(){
	currentNews++;
	if(currentNews > newsLength) { currentNews = 1; }
	

	var currNewsDiv = '#news_'+currentNews+'_div';
	$('#newsticker>div').hide();
	//if($(currNewsDiv).hasClass('title')){
		$(currNewsDiv).fadeIn(1).animate({left:"-=214px"},751,'easeOutQuad')
							.animate({left:"-=0px"},2911,'easeOutQuad')
							.animate({left:"-=674px"},1051,'easeInQuad');
		$(currNewsDiv).css({left: '200px'});
	//} else {
		//$(currNewsDiv).fadeIn(911);
	//}
	
	aut = setTimeout("autoPlayNews()", 8500);
}

$(document).ready(function() {
		lengthLI = $('#countrytabs li').length;
		rightSideLength = $('.sidebar-inner >div').length;
		newsLength = $('#newsticker>div').length;
		
		autoPlay();
		autoPlayRight();
		autoPlayNews();
		
		$('#countrytabs li').livequery('click',function(i){
			$('#countrytabs li>a').each(function(){
				$(this).removeClass('selected');
			});
			//console.log($(this).attr('name'));
			clearTimeout(aut);
			currentLI=($(this).attr('name'))-1;		
			//currentLI = 0;
			$(this+' >a').addClass('active');
			var featured_proj = $(this).attr('id')+'_div';
			$('.content-inner>div').hide();
			$('#'+featured_proj).fadeIn(500,function(){
				//autoPlay();
			});
		});
		
		
});

