$(document).ready(function() {
	function megaHoverOver(){
		$(this).find(".sub").stop().fadeTo('fast', 1).show();
			
	}
	
	function megaHoverOut(){ 
	  $(this).find(".sub").stop().fadeTo('fast', 0, function() {
		  $(this).hide(); 
	  });
	}
	var config = {    
		 sensitivity: 2, // number = sensitivity threshold (must be 1 or higher)    
		 interval: 100, // number = milliseconds for onMouseOver polling interval    
		 over: megaHoverOver, // function = onMouseOver callback (REQUIRED)    
		 timeout: 0, // number = milliseconds delay before onMouseOut    
		 out: megaHoverOut // function = onMouseOut callback (REQUIRED)    
	};

	$("ul#nav1 li .sub").css({'opacity':'0'});
	$("ul#nav1 li").hoverIntent(config);
	
	$("ul#nav2 li .sub").css({'opacity':'0'});
	$("ul#nav2 li").hoverIntent(config);
	
	$(".choix-offres").selectbox();
	
	$( "#tabs" ).tabs({
			event: "click"
		});
    
	function mycarousel_initCallback(carousel)
{
    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
};

jQuery('#mycarousel').jcarousel({
        auto: 2,
        scroll: 1,
        wrap: 'circular',
        buttonNextHTML: '',
        buttonPrevHTML: '',
        visible: 5,
        initCallback: mycarousel_initCallback
    });

if($("#nos-ref").length>0){
	$("#nos-ref").easySlider({
					auto: true, 
					continuous: true
				});
}
		
if($("#contact-popup").length>0){
$("#contact-popup").fancybox({
				'transitionIn'		: 'none',
				'titleShow' : false,
				'transitionOut'		: 'none'
			});
}		
if($("#telecharger-doc").length>0){
$("#telecharger-doc").fancybox({
				'transitionIn'		: 'none',
				'titleShow' : false,
				'transitionOut'		: 'none'
			});
}
	
function initMenu() {
  $('#col-gauche ul li ul').hide();
  $('#col-gauche li a').click(
    function() {
        $(this).next().slideToggle('normal');	
      }
    );
  }
$(document).ready(function() {initMenu();});

$(".selectionsubmit").hover(function(){     
       $(this).addClass("selectionsubmit-hover");    
   },     
   function(){    
       $(this).removeClass("selectionsubmit-hover");     
    });
	
	$(".nlsubmit").hover(function(){     
       $(this).addClass("nlsubmit-hover");    
   },     
   function(){   
       $(this).removeClass("nlsubmit-hover");     
    });
	
	$(".nlsubmit-header").hover(function(){     
       $(this).addClass("nlsubmit-header-hover");    
   },     
   function(){    
       $(this).removeClass("nlsubmit-header-hover");     
    });
	
	$(".contact-submit").hover(function(){     
       $(this).addClass("contact-submit-hover");    
   },     
   function(){    
       $(this).removeClass("contact-submit-hover");     
    });
	
	
	if($(".contact_form").length > 0){ 
		$(".contact_form").validate({
			errorContainer: "div.error",
			debug:false
		})
	}
	
	if($("#contact_form.publishing_contact").length > 0){
		$("#contact_form.publishing_contact").validate({
			submitHandler: function(form){
				$.ajax({
					type: "POST",
					url: '/publications/contact',
					data: $(form).serialize(),
					success: function(data){
						$('.message-confirm-telechargement').show();
						$('.publishing_contact').hide();
						$('#telecharger-doc').attr('href', data.fichier);
						$('.download').attr('href', data.fichier);
						$('#telecharger-doc').unbind('click.fb');
						_gaq.push(['_trackEvent', 'Formulaire telechargement', 'Publication', data.fichier]);
					}
				});
			}, 
			errorContainer: "div.error",
			debug:false
		})
	}
	
	if($("#contact_form.form_ajax").length > 0 ){
		$("#contact_form.form_ajax").validate({
			submitHandler: function(form){
				$.ajax({
					type: "POST",
					url: '/contact',
					data: $(form).serialize(),
					success : function(data){ 
						var tpl=data.message; 
						document.forms['contact_form'].reset(); 
						$('.retour-frm-contact') .html(tpl) .slideDown(150) .delay(5000) .slideUp(150,function(){
							$(this).find('.message-confirm-popup').remove();
							$.fancybox.close();
						}); 
						
					}
				});
			}, 
			errorContainer: "div.error",
			debug:true
		})
	}
	
	$("#col-gauche ul li").hover(function(){     
       $(this).addClass("sous-nav1-hover");    
   },     
   function(){    
       $(this).removeClass("sous-nav1-hover");     
    });
	
	$("#col-gauche ul li ul li").hover(function(){     
       $(this).addClass("sous-nav2-hover");    
   },     
   function(){    
       $(this).removeClass("sous-nav2-hover");     
    });
   
	if($('#form-newsletter-header').length > 0 ){
	   $('#form-newsletter-header').validate({ errorPlacement: function(error, element) { error.appendTo( element.parent("form") ); }, 
	    messages : { 'email-newsletter' : "Votre email ne semble pas valide" }, 
		submitHandler: function(form){ $.ajax({ 
			type: "POST",
			url : '/newsletter/inscription', 
			data : $('#form-newsletter-header').serialize(), 
			success : function(data){
				var tpl=data.message;
				if(data.status == 'ok'){
					window.location.href='/newsletter/confirmation';
				} else {
					$('.retour-frm-newsletter').html(tpl).slideDown(150).delay(5000).slideUp(150,function(){
						$(this).find('.messages').remove(); 
					}); 
				}
			} 
		}); } });
	}
   
   
	$('#inscription-newsletter-footer').validate({ errorPlacement: function(error, element) { error.appendTo( element.parent("form") ); }, 
	messages : { 'email-newsletter' : "Votre email ne semble pas valide" }, 
	submitHandler: function(form){ $.ajax({ 
	type: "POST",
	url : '/newsletter/inscription', 
	data : $('#nl-inscription-champ').serialize(), 
	success : function(data){ 
		var tpl=data.message;
		if(data.status == 'ok'){
			window.location.href='/newsletter/confirmation';
		} else {
			var tpl=data.message; $('.retour-frm-newsletter2') .html(tpl) .slideDown(150) .delay(5000) .slideUp(150,function(){ $(this).find('.messages').remove(); }); 
		}
	} }); } });
			
});
