/*
 * Author : Cvetozar Ninov
 * Email  : cninov@gmail.com
 * */
$(function() {
$(".leagues_match_accent div").jCarouselLite({
    btnNext: ".next_accent",
    btnPrev: ".prev_accent",
    speed: 200,
    visible: 10,
    scroll: 1,
    circular: false
});
});

function __triger_mouse_enter_leagues() {
		clearTimeout(t);
		index_leagues_to_show++;
		var cnt = $(".leagues_match_accent li").length;
		if(index_leagues_to_show >= cnt) {
			index_leagues_to_show=0;
		}
		
		$(".leagues_match_accent li.current_league").removeClass("current_league");
		$(".leagues_match_accent li:eq("+index_leagues_to_show+")").addClass("current_league")
		var league_id = $(".leagues_match_accent li.current_league").attr("id").replace("match_league_","");
		$.get(_root+'xhr?method=league_news',{league_id: league_id},function(data){
			$('.news_accent').remove();
			$('.latest_news_items').html(data.ul);
			$('ul.latest_news_items').before(data.html);
			$('#news_accent_caroucel h2').html('<a href="'+_site_url+'roundup/index/'+league_id+'">'+$('#match_league_'+league_id+' a').attr('title')+'</a>');
			stop_image_rotation=0;
			index_news=0;
			clearTimeout(t);
			setTimeout(function(){__triger_mouse_enter();},rotate_by/2);
		},'json');
}

$(document).ready(function(){
	$(".leagues_match_accent li").bind("click",function(){
		index_leagues_to_show = $(".leagues_match_accent li").index(this);
		index_leagues_to_show--;
		stop_image_rotation=1;
		index_news=0;
		__triger_mouse_enter_leagues();
	});
	
	$('#news_accent_caroucel h2').html('<a href="'+_site_url+'roundup/index/'+$('.leagues_match_accent li:first').attr('id').replace('match_league_','')+'">'+$('.leagues_match_accent li:first a').attr('title')+'</a>');
});