jQuery.noConflict();

jQuery(document).ready(function($){

function testFieldAutreBiai(){
		if($('#question_biais').length){
			$('#question_biais option:selected').each(function () {
				//alert(this.value);
	            if(this.value=='Autre'){
	            	$('#autre_biai').parent().show();
	            }else{
	            	$('#autre_biai').parent().hide();
	            }
	        });
		}
	}
	
	testFieldAutreBiai();
	
	$('#question_biais').change(function(){
		testFieldAutreBiai();
	}).trigger('change');

	if($("#form_webcallback").length){
		$("#form_webcallback").validate();
    }
	
    var newsletter = 'votre email';
    $("#newsletter").attr('value',newsletter);

    $("#newsletter").attr('value',newsletter).focus(function () {
        if (this.value == newsletter) this.value = '';
    }).blur(function () {
        if (this.value == '') this.value = newsletter;
    });
    
    $('#header .menu>ul>li').hover(function() {
        $(this).addClass('jHover');
    }, function() {
        $(this).removeClass('jHover');
    });
    
    $('#header .menu>ul>li>a').focus(function() {
        $('#header .menu>ul>li').removeClass('jHover');
        $(this).parent().addClass('jHover');
    });
    
    $('#colLeft .ariane a, #header .menu>a').focus(function() {
        $('#header .menu>ul>li').removeClass('jHover');
    });
    
    $('#colLeft h2.titreVillages a').addClass('plie').parent().next().hide();
    
    $('#colLeft h2.titreVillages a').click(function() {
        $(this).toggleClass('plie');
        $(this).parent().next().slideToggle();
        $(this).blur();
        return false;
    });


    /* Gestion du Carroussel */
    var marge = $("#content .blocGalerie .photo .galerie .masque .image").outerWidth(true);
    var animationActive = false;
    
    $("#content .blocGalerie .photo .galerie .flechePrev").click(function(){
        if (!animationActive)
        {
            animationActive = true;
            $("#content .blocGalerie .photo .galerie .masque .image:last").clone().insertBefore("#content .blocGalerie .photo .galerie .masque .image:last");
            $("#content .blocGalerie .photo .galerie .masque .image:last").insertBefore("#content .blocGalerie .photo .galerie .masque .image:first");
            $("#content .blocGalerie .photo .galerie .slider").css("left", "-"+marge+"px");
            $("#content .blocGalerie .photo .galerie .slider").animate({"left": "+="+marge+"px"}, 500, "swing", function() {
                $("#content .blocGalerie .photo .galerie .masque .image:last").remove();
                animationActive = false;
            });
        }
        this.blur();
        return false;
    });
    
    $("#content .blocGalerie .photo .galerie .flecheSuiv").click(function(){
        if (!animationActive)
        {
            animationActive = true;
            $("#content .blocGalerie .photo .galerie .masque .image:first").clone().insertAfter("#content .blocGalerie .photo .galerie .masque .image:first");
            $("#content .blocGalerie .photo .galerie .masque .image:first").insertAfter("#content .blocGalerie .photo .galerie .masque .image:last");
            $("#content .blocGalerie .photo .galerie .slider").animate({"left": "-="+marge+"px"}, 500, "swing", function() {
                $("#content .blocGalerie .photo .galerie .masque .image:first").remove();
                $("#content .blocGalerie .photo .galerie .slider").css("left", "0px");
                animationActive = false;
            });
        }
        this.blur();
        return false;
    });
    
    // Autoslide
    /*
    if ($("#actuDefilBloc").is('.autoSlide')){
        var interval = setInterval(function() { $('#actuDefilSuiv').click(); }, 4000);
        $('#actuDefilBloc').bind('mouseover', function(){ clearInterval(interval); });
    }
    */
    
    
/*
    $("#imprimer").click(function(){
        window.print();
        this.blur();
        return false;
    });
    
    // Gestions des carrousels :
    
    $(".blocSlider").each(function(){
    
        var current = $(this);
        var menuMargin = 0;
        
        if ( current.parent().parent().attr("class") == 'lightBox' )
        {
            var marge = 76;
            var largeurSlider = 590;
        }
        else
        {
            var marge = current.find(".slider a").outerWidth(true);
            var largeurSlider = current.find(".masqueSlider").width();
        }
        
        var longueurSlide = ( current.find(".slider a").length * marge ) - largeurSlider - marge;
 
        current.children(".sliderPrec").click(function(){
            if ( menuMargin > 0 )
            {
                current.find(".masqueSlider .slider").animate({"left": "+="+marge+"px"}, "slow", "swing");
                menuMargin = menuMargin - marge;
            }
            this.blur();
            return false;
        });

        current.children(".sliderSuiv").click(function(){
          if ( menuMargin <= longueurSlide )
          {
            current.find(".masqueSlider .slider").animate({"left": "-="+marge+"px"}, "slow", "swing");
            menuMargin = menuMargin + marge;
          }
          this.blur();
          return false;
        });
    });
    
    // Gestion des descriptifs photos et vid�o
    
    $("#sliderPhoto a").bind("mouseover", function(){
        // ou chargement des textes en ajax
        var divContent = $("#descPhoto");
        var divContentReplace = $(this).find('.descPhoto').html();
        divContent.html(divContentReplace);
    });
    
    $("#sliderVideo a").click(function(){
        // ou chargement des textes et images en ajax
        var descVideo = $("#descVideo");
        var apercuVideo = $("#apercuVideo");
        var divContentReplaceTxt = $(this).find('.descVideo').html();
        var divContentReplaceImg = $(this).find('.imageURL').text();
        descVideo.html(divContentReplaceTxt);
        apercuVideo.attr('src', 'img/'+divContentReplaceImg);
        
        this.blur();
        return false;
    });
    
    */

});