/******** NAVIGATION ********/
$(document).ready(function()
{
	// $('#sports_prec').html($('.prec0').html());
	// $('#sports_suiv').html($('.suiv0').html());
	// $('.prec').hide();
	// $('.suiv').hide();
	handleCycleScroll(500);
	handleCycleScrollEncemoment(500);
	handleShowSportName();
	handlePlayVOD();
});

$(function() {
	$('#menu_sports li').hover(function(){
		$(this).css('background-color','#99FF99');
//		$('#sport_affiche').html($(this).html());
		$('#sport_affiche').html($(this).find('p.nom_sport').html());
	}, function(){
		$(this).css('background-color','');
		$('#sport_affiche').html('');
	});
});

$(function() {
	$('.numPage').click(function() {
		$('.blocTexte').hide();
		$('#'+$(this).attr('id')+'Page').show();
		$('#sports_prec').html($('#'+$(this).attr('id')+'Page').find('.prec').html())
		$('#sports_suiv').html($('#'+$(this).attr('id')+'Page').find('.suiv').html())

		// on compte chez cybermétrie
/*		cybermetrieGenerate = new Image();
		rubrique = "france2_programmes_toutlemondeveutprendresaplace_accueil";
		cybermetrieGenerate.src = 'http://stat3.cybermonitor.com/france2_v?R=' + rubrique + '&S=total;france2_programmes_toutlemondeveutprendresaplace';
*/	});
});


/*$.get("index-fr.php?page=ajax_navigation",function(data){
	alert(data);
//	alert(data);
//	infos = data;
//	infos.find('#menu_sports').appendTo('#sport_affiche');

//	$('#sport_affiche').html(data);
}, 'XML');
*/


/******** FIL INFO ********/

var pas = 650;
var posNow = 0;
var target = false;
var largeurFil = false;
$(window).load(function()
{
	filInfo();
});

function filInfo()
{
	target = $('#fil_infos');
	nbFil = $('#fil_infos li').length;
	largeurFil = nbFil*pas;
	setTimeout("filInfoMove()", 7000);
}

function filInfoMove()
{
	posNow = posNow+pas;
	if(posNow >= largeurFil)
	{
		posNow = 0;
		//target.scrollLeft(0);
		target.animate({scrollLeft: posNow}, 1000);
		setTimeout("filInfoMove()", 7000);
	}
	else
	{
		target.animate({scrollLeft: posNow}, 1000);
		setTimeout("filInfoMove()", 7000);
	}
}

/******** Navigation TOP ********/

function handleShowSportName()
{
	$('.showSportName').mouseover(function(e)
	{
		position = e.pageX - $('.thumbsContent').offset().left; // il faudrait calculé la marge à gauche non pas en fonction de e mais de la bordure gauche du site
		$('.sportname').css('margin-left', position+'px');
		$('.sportname').html($(this).attr("alt"));
		$('.sportname').show();
	});
	
	$('.showSportName').mouseout(function()
	{
		$('.sportname').hide();
	});
}

/******** Player VOD Home ********/

function handlePlayVOD()
{
	$('.play').click(function()
	{
		directPlay();
		return false;
	});
}

function directPlay()
{
	$('.play').hide();
	$('.boutons').hide();
	$('.media').media({
		width:     288,
		height:    229,
		autoplay:  true,
		caption:   false
	});
}

function handleCycleScroll(speed) {
	$(".thumbsContent").cycle({fx: "scrollHorz", speed: speed, timeout: 0, next: ".jsTnScrollerLeftLnk", prev: ".jsTnScrollerRightLnk"});
}

function handleCycleScrollEncemoment(speed) {
	$(".thumbsContentEncemoment").cycle({fx: "scrollHorz", speed: speed, timeout: 0, next: ".jsTnScrollerLeftLnkEncemoment", prev: ".jsTnScrollerRightLnkEncemoment"});
}



