$(window).load(function(){

	$("#featured").carousel({
		pagination: true,
		loop: false
	});
	
	$(".home #content .actus .post").each(function(){
		var post = $(this);
		var link = post.find("h3 a").attr("href");
		post.click(function(){
			window.location.href = link;
		});	
	});
	
	$("#menu .menu-item").each(function(){
		var elmt = $(this);
		if(elmt.has(".sub-menu")){
			
		}
	});
	
	$("#menu .menu-item").each(function(){
		var elmt = $(this);
		var sub = elmt.find(".sub-menu");
		if(sub.length){
			elmt.find("a:eq(0)").css("cursor", "default").removeAttr("href");
		}
		sub.hide();
		elmt.hover(function(){
			sub.show().stop().fadeTo(0, 0).fadeTo(200, 1);
		}, function(){
			sub.stop().fadeTo(200, 0, function(){
				sub.hide();
			});
		});
	});
	
	$("#carousel").each(function(){
		
		var elmt = $(this);
		var big = elmt.find("#bigImage");
		var w = big.width();                  
		big.find("a").each(function(e){
			$(this).css("left", e*w);
		});
		var nav = elmt.find(".navigation");
		var lis = elmt.find("li");
		var max = lis.length;
		lis.each(function(i){	
			var li = $(this);
			var a = li.find("a");
			a.click(function(){
				big.find("a").each(function(e){
					$(this).animate({
						"left": -(w*(i-e))
					}, 150);                     
				});
				a.addClass("active");
				lis.each(function(){
					$(this).find("a").not(a).removeClass("active");
				});				
				return false;
			});
		});
		lis.find("a").eq(0).click();
		
	});
	
    $(".wp-caption").width(function() {
        return $('img', this).width();  
    });
	
	
	$("a.fancybox, a[href$='.jpg'], a[href$='.jpeg'], a[href$='.png'], a[href$='.gif'].").attr('rel', 'gallery').fancybox({
		'margin': 20,
		'padding': 0,
		'overlayShow'	: true,
		'overlayOpacity': 0.5,
		'overlayColor'	: '#E9EAEA',
		'titleShow'	: false
	});
	
	/*******************/
/*   GESTION DE L'aFFICHAGE DE PRE-HOME en cookie*/
/*******************/

	jQuery(document).ready(function(){
		
		
		$(function(){ 
			$("#hidden_link").each(function() {
		
					$(this).fancybox({
					'speedIn'		:	500, 
					'speedOut'		:	300, 
					'hideOnContentClick'	: true,
					'overlayOpacity'	:	0.8
					}).trigger('click');
				
			});
		});
		
	});





});
