function setCookie(nom,valeur,jours) {
	var expDate = new Date();	
	expDate.setTime(expDate.getTime() + (jours * 24 * 3600 * 1000));
	document.cookie = nom + "=" + escape(valeur) + ";expires=" + expDate.toGMTString();
}
	
function getCookie(nom) {
	deb = document.cookie.indexOf(nom + "=")
	if (deb >= 0) {
		deb += nom.length + 1
		fin = document.cookie.indexOf(";",deb)
		if (fin < 0) fin = document.cookie.length
			return unescape(document.cookie.substring(deb,fin))
	}
	return ""
}


$(document).ready(function(){
	
	var tab_cookie = getCookie('onglet');
	if(tab_cookie != ''){
		$(".active").removeClass("active");
		$('[title='+tab_cookie+']').addClass("active");
		$(".tab_content").fadeOut();
		$("#" + tab_cookie).fadeIn();
	}
	
	/* info fichier sous-titres */
	$('a.dl_link').hover(function() {
		var info = $(this).children('span').html();
		var about = '<div id="about">'+
					'<h5 class="info_title">Informations :</h5>'
					+'<p>'
					+info
					+'</p>'
					+'</div>';
		$(this).append(about).children('#about').hide().fadeIn(500);
	}, function(){
		$('#about').remove();
	});
	
	/* onglets */
	$("#tabs_titles a").click(function () {
		$(".active").removeClass("active");
		$(this).addClass("active");
		$(".tab_content").fadeOut();
		var contenu_aff = $(this).attr("title");
		$("#" + contenu_aff).fadeIn();
		setCookie('onglet', '', -1);
		setCookie('onglet', contenu_aff, 365);
		return false;
	});
	
	/* filtres vf/vo */
	$('#l_ep_vf').click(function(){
		$('.episode_vf').fadeIn("fast");
		$('.episode_vo').fadeOut("fast");
		return false;
	});
	$('#l_ep_vo').click(function(){
		$('.episode_vo').fadeIn("fast");
		$('.episode_vf').fadeOut("fast");
		return false;
	});
	$('#l_all_ep').click(function(){
		$('.episode_vf').fadeIn("fast");
		$('.episode_vo').fadeIn("fast");
		return false;
	});
	
	/* toolbox */
	var a=null;
	$('#admin_shortcuts').mouseenter(function(){
		clearTimeout(a);
		$(this).stop().animate({marginRight: 0});
	}).mouseleave(function(){
		a=setTimeout(function(){
			$('#admin_shortcuts').stop().animate({
				marginRight: "-190px"
			});
		}, 600);
	});
	
	/* info request */
	$('.info_request').hover(function() {
		$(this).children('span')
				.css({
					'display': 'block',
					'position': 'absolute',
				})
				.hide().fadeIn(500);
	}, function(){
		$(this).children('span').hide();
	});
	
});