$(document).ready(function()
{
	//On cache toutes les listes de vidéo.
	$('.listeVideoLayout').hide();

	//Pour chaque liste de vidéo, on récupère le premier onglet et on l'affiche.
	$(".videosTri").each(function()
	{
		var onglet=$(this).find('.ongletTri:first');
		onglet.addClass('active');
		var id=onglet.attr('href');
		$(id).show();
	});
	
	$(".ongletTri").click(function()
	{
		var parent=$(this).parent().parent().parent();
		parent.children('.listeVideoLayout').each(function(){$(this).hide()});

		//On affiche l'onglet
		var id=$(this).attr('href');
		$(id).show();

		parent.find('.ongletTri').removeClass('active');
		$(this).addClass('active');

		return false;
	});
	
	$('.vignetteLayoutActu').click(function(){			
		var parent=$(this).parent('.tinyVideoActu');
		var id=parent.find('.loadingLayoutActu').attr('title');		
		var larg = parent.find('.videoLayoutActu').width();
		var haut = parent.find('.videoLayoutActu').height();
		$(this).hide();
		parent.find('.loadingLayoutActu').css('display','block');
		parent.animate({width: larg, height: haut+20}, 500, "linear", function(){
			parent.find('.loadingLayoutActu').hide();
			parent.find('.videoLayoutFermer').css('display','block');
			parent.find('.videoLayoutActu').css('display','block');
			});
		writeStats(id);
	});
	
	$('.videoLayoutFermer').click(function(){			
		var parent=$(this).parent('.tinyVideoActu');;
		var larg = parent.find('.vignetteLayoutActu').children('.vignette:first').css('width');
		var haut = parent.find('.vignetteLayoutActu').children('.vignette:first').css('height');
		$(this).hide();
		parent.find('.videoLayoutActu').hide();
		var temp=parent.find('.videoLayoutActu').html();
		parent.find('.videoLayoutActu').html(temp);
		parent.find('.loadingLayoutActu').css('display','block');				
		parent.animate({width: larg, height: haut}, 500, "linear", function(){
			parent.find('.loadingLayoutActu').hide();
			parent.find('.vignetteLayoutActu').show();
			});		
	});
});

function reload(obj,id)
{
	obj.attr('src',tUrlVideo[id]);
}

function writeStats(id)
{
	var action='/index.php?module=videos&action=videos:writeStats&id_content='+id;
	$.ajax({
	 	url: action,
	  	dataType: "text"
	});	
}
