/*
	Modules tennis ajax avec onglets et carousels inclus (requiert jquery.js et timer.js)
*/

$(document).ready(function(){

// the tabs
	the_tabs();
	
// the carousel
	the_carousel();

// module tennis
	if ($("#the-tennis").length!=0) {
		change_module_tennis();
		$.timer(120000, change_module_tennis);
	}

}); // End dom ready

function change_module_tennis(){
	$("#chelem-live").load("/cache/rolandgarros/scoreboard_wim_sp.shtml?random"+Math.random(),function() {
		the_tabs();
		the_carousel();
	});
}

function the_tabs() {
	$(".content-of-tab").not(":first").hide();
	$("ul.the-tabs li:first").addClass("the-current");
	$(".content-of-tab:first").addClass("the-current"); 
	$("ul.the-tabs a").click(function(){ 
	  $("ul.the-tabs a").parents("li").removeClass("the-current"); 
	  $(".content-of-tab").hide(); 
	  $(this.hash).show(); 
	  $(this).blur().parents("li").addClass("the-current");
	  event.stopPropagation();
	});
}

function the_carousel(){
	$(".content-of-tab ul").each(function(){
		$(this).children("li:gt(2)").hide();
	});
	$(".prev-match").hide();
	$(".next-match").click(function(){
		bouton = $(this);
		$(bouton).siblings(".prev-match, .next-match").show();
		currentTab = $(bouton).parents(".default-block-inner").children(".content-of-tab:visible");
		if (currentTab) {
			next = $(currentTab).children("ul").children("li:visible:last").nextAll().slice(0, 3);
			if (next.length > 0) {
				$(currentTab).children("ul").children("li:visible").hide();
				next.show();
				next2 = $(currentTab).children("ul").children("li:visible:last").nextAll().slice(0, 3);
				if (next2.length == 0) {
					$(bouton).css('visibility','hidden');
				}
			}
		}
	});
	$(".prev-match").click(function(){
		bouton = $(this);
		$(bouton).siblings(".prev-match, .next-match").show();
		currentTab = $(bouton).parents(".default-block-inner").children(".content-of-tab:visible");
		if (currentTab) {
			prev = $(currentTab).children("ul").children("li:visible:first").prevAll().slice(0, 3);
			if (prev.length > 0) {
				$(currentTab).children("ul").children("li:visible").hide();
				prev.show();
				prev2 = $(currentTab).children("ul").children("li:visible:first").prevAll().slice(0, 3);
				if (prev2.length == 0) {
					$(bouton).css('visibility','hidden');
				}
			}
		}
	});
}
