// JavaScript Document
$(document).ready(function() {

	/* affichage du menu */
	var paddingUlMenu = 10; 
	function megaHoverOver(){
		$(this).find(".sub").stop().fadeTo('fast', 1).show();
		(function($) {
			jQuery.fn.calcSubWidth = function() {
				rowWidth = 0;
				$(this).find("ul").each(function() {
					rowWidth += $(this).width()+paddingUlMenu;
				});
			};
		})(jQuery); 
		if ( $(this).find(".row").length > 0 ) {
			var biggestRow = 0;	
			$(this).find(".row").each(function() {
				$(this).calcSubWidth();
				if(rowWidth > biggestRow) {
					biggestRow = rowWidth;
				}
			});
			$(this).find(".sub").css({'width' :biggestRow});
			$(this).find(".row:last").css({'margin':'0'});
		} else {
			$(this).calcSubWidth();
			$(this).find(".sub").css({'width' : rowWidth});
		}
	}
	function megaHoverOut(){
	  $(this).find(".sub").stop().fadeTo('fast', 0, function() {
		  $(this).hide();
	  });
	}
	var config = {
		 sensitivity: 2,
		 interval: 100,
		 over: megaHoverOver,
		 timeout: 500,
		 out: megaHoverOut
	};
	$("ul#menu li .sub").css({'opacity':'0'});
	$("ul#menu li").hoverIntent(config);
	
	$('a.noClick').click(function(){
		return false;	
	});
	
	/* ouverture des boites */
	function toggle($Box){
		$H4 = $Box.find('h4');
		$Fleche = $Box.find('.fleche');
		$Cont = $Box.find('.contenuEncart');
		$Bg = $Box.find('.bgcontenuEncart');
		bVisible = ($Bg.is(':visible')) ? true : false;
		
		if(bVisible){ /* cacher box */
			$Box.css({'background':'none repeat scroll 0 0 #232323','padding-bottom':'0'});
			$H4.css('background', 'url("images/encarts/encarts-fermes/encart-titre.jpg") no-repeat scroll center top transparent');
			$Fleche.css('background','url("images/encarts/fleche.png") no-repeat scroll center top transparent'); 
			$Cont.css({'background':'url("images/encarts/encarts-fermes/encart-bas.jpg") no-repeat scroll center bottom transparent', 'padding-bottom' : '11px'});
		
		}else{		/* montrer box */
			$Box.css({'background':'url("images/encarts/encarts-ouverts/footer-encart-ouvert.png") no-repeat scroll center bottom #232323','padding-bottom':'14px'});
			$H4.css('background', 'url("images/encarts/encarts-ouverts/encart-titre.jpg") no-repeat scroll center top transparent');
			$Fleche.css('background','url("images/encarts/fleche-bas.png") no-repeat scroll center top transparent'); 	
			$Cont.css({'background':'url("images/encarts/encarts-ouverts/bg-encart-ouvert.png") repeat-y scroll center top transparent', 'padding':0});
			$Bg.css('background','url("images/encarts/encarts-ouverts/bgcontenu-encart-ouvert.jpg") no-repeat scroll center top transparent');
			
		}
		
		$Bg.slideToggle('slow');
	}
	
	$('.encart_carre .bgcontenuEncart').hide();
	$('.encart_carre .displayBox').click(function() { 
		$Box = $(this).closest('.encart_carre');
		toggle($Box);
		return false;
	});
		
	/* défilement des partenaires */
	$("#jMyCarousel").jMyCarousel({ 
		vertical: true,  
        auto: true,
		eltByElt: false,
		speed: 1000,
		circular : true
	});  
	$("#jMyCarouselUp").jMyCarousel({  
        vertical: true,  
        auto: true,
		eltByElt: true,
		speed: 10000,
		easing:'easeOutElastic',
		up:true
    }); 
	$("#jMyCarouselPrincipal").jMyCarousel({  
        auto: true,
		eltByElt: false,
		speed: 8000,
		circular : true,
		visible:'100%'
    }); 
	
	/* nyromodal */
	//$('.nyroModal').nyroModal();
	
});
