$(document).ready(function(){

	$(".BVvideoSelectionable").live("mouseover",function(e){
		$(this).addClass("hover");
		$(".BVbandeNoireInfo a").html($(this).find("img").metadata({type:'attr',name:'data'}).pseudo);
		$(".BVbandeNoireInfo em").html($(this).find("img").metadata({type:'attr',name:'data'}).timestamp);
		$(".BVbandeNoireInfo .titre_vignette").html($(this).find("img").metadata({type:'attr',name:'data'}).titre);
		$(".BVbandeNoireInfo").css("top", (e.pageY - 50) + "px").css("left",(e.pageX + 10) + "px").show();
	});
	
	$(".BVvideoSelectionable").live("mousemove",function(e){
		$(".BVbandeNoireInfo").css("top", (e.pageY - 50) + "px").css("left",(e.pageX + 10) + "px").show();
	});
	
	$(".BVvideoSelectionable").live("mouseout", function(){
		$(this).removeClass("hover");
		$(".BVbandeNoireInfo").hide();	
	});
						   
	$(".BVvideoSelectionable").live("click", function(){
		nb = parseInt($(this).attr("nb"));
		c = parseInt($(this).attr("indice"));
		remonte_media_id = parseInt($(this).attr("val"));
		
		if (c <= 0)
		{
			$(".BVflecheGaucheActive").css("display", "none");
			$(".BVflecheGaucheInactive").css("display", "block");
		}
		else
		{
			if ($(".BVflecheGaucheActive").css("display") == "none")
			{
				$(".BVflecheGaucheInactive").css("display", "none");
				$(".BVflecheGaucheActive").css("display", "block");
			}
		}

		if (c >= (nb - 1))
		{
			$(".BVflecheDroiteActive").css("display", "none");
			$(".BVflecheDroiteInactive").css("display", "block");
		}
		else
		{
			if ($(".BVflecheDroiteActive").css("display") == "none")
			{
				$(".BVflecheDroiteInactive").css("display", "none");
				$(".BVflecheDroiteActive").css("display", "block");
			}
		}

		$("#playerContentLeft").load("/index_player.php", {'remonte_media_id': remonte_media_id, 'autostart': "true"});
		$(".BVvideoSelectionnee").removeClass("BVvideoSelectionnee").addClass("BVvideoSelectionable");
		$(this).removeClass("hover").removeClass("BVvideoSelectionable").addClass("BVvideoSelectionnee");
		$(".BVbandeNoireInfo").hide();	

		return false;
	});

	$(".BVflecheDroiteActive").live("click",function(e){
		nb = parseInt($(".BVflecheDroiteActive").attr("nb"));
		cur = parseInt($(".BVvideoSelectionnee").attr("indice"));
		next = cur + 1;

		el = $(".BVvideoSelectionnee + .BVvideoSelectionable");
		remonte_media_id = parseInt(el.attr("val"));

		if (el.css("display") == "none")
		{
			d = next - 9;
			$("div[indice='" + d + "']").css("display", "none");
			el.css("display", "block");
		}

		if (next >= (nb - 1))
		{
			$(".BVflecheDroiteActive").css("display", "none");
			$(".BVflecheDroiteInactive").css("display", "block");
		}

		if ($(".BVflecheGaucheActive").css("display") == "none")
		{
			$(".BVflecheGaucheInactive").css("display", "none");
			$(".BVflecheGaucheActive").css("display", "block");
		}

		$("#playerContentLeft").load("/index_player.php", {'remonte_media_id': remonte_media_id});
		$(".BVvideoSelectionnee").removeClass("BVvideoSelectionnee").addClass("BVvideoSelectionable");
		el.removeClass("hover").removeClass("BVvideoSelectionable").addClass("BVvideoSelectionnee");
		$(".BVbandeNoireInfo").hide();	
		return false;
	});

	$(".BVflecheGaucheActive").live("click",function(e){
		nb = parseInt($(".BVflecheGaucheActive").attr("nb"));
		cur = parseInt($(".BVvideoSelectionnee").attr("indice"));
		prev = cur - 1;

		el = $("div[indice='" + prev + "']");
		remonte_media_id = parseInt(el.attr("val"));

		if (el.css("display") == "none")
		{
			d = prev + 9;
			$("div[indice='" + d + "']").css("display", "none");
			el.css("display", "block");
		}

		if ($(".BVflecheDroiteActive").css("display") == "none")
		{
			$(".BVflecheDroiteInactive").css("display", "none");
			$(".BVflecheDroiteActive").css("display", "block");
		}

		if (prev <= 0)
		{
			$(".BVflecheGaucheActive").css("display", "none");
			$(".BVflecheGaucheInactive").css("display", "block");
		}

		$("#playerContentLeft").load("/index_player.php", {'remonte_media_id': remonte_media_id});
		$(".BVvideoSelectionnee").removeClass("BVvideoSelectionnee").addClass("BVvideoSelectionable");
		el.removeClass("hover").removeClass("BVvideoSelectionable").addClass("BVvideoSelectionnee");
		$(".BVbandeNoireInfo").hide();	
		return false;
	});

	$("#toutlire").live("click",function(e){

		$("#playerContentLeft").load("/index_player_all.php");
		$(".BVbandeNoireInfo").hide();	
		return false;
	});
					
})
