/*
**  Utilisation de la librairie jQuery
**  http://docs.jquery.com/Downloading_jQuery#Download_jQuery
*/

jQuery.noConflict();
jQuery(function($) {
	
	
	jQuery.fn.fadeToggle = function(speed, easing, callback) {
		   return this.animate({opacity: 'toggle'}, speed, easing, callback);

		}; 

    // Vide le champs au focus.
    function clearInput(_item) {
        $(_item).focus(function() {
            if(this.value == this.defaultValue) {
                this.value = "";
            }
        }).blur(function() {
            if(!this.value.length) {
                this.value = this.defaultValue;
            }
        });
    }
    clearInput('.clearInput');
    
    // Gestion du menu
    $('.nav > li').hoverIntent({
        sensitivity: 7, // number = sensitivity threshold (must be 1 or higher)
        interval: 100,  // number = milliseconds of polling interval
        over: showNav,  // function = onMouseOver callback (required)
        timeout: 300,   // number = milliseconds delay before onMouseOut function call
        out: hideNav    // function = onMouseOut callback (required)
    });
    function showNav() {
        $(this).addClass('active').find('.subNav').show();
    }
    function hideNav() {
        $(this).removeClass('active').find('.subNav').fadeOut('fast');
    }
    
    // Corection IE du menu
    if($.support.cssFloat==false) {
        $('.nav > li').each(function () {
            var myWidth = $(this).width()-2;
            $(this).find('.subNav').width(myWidth); 
        });
    }
        
    // Gestion accueil slideShow
    $('#noJavascript').hide();
    $('.secondNav ul li.first').css('display', 'none');
    
    
    if($('#thumbs').length){
    	
		// Initially set opacity on thumbs and add
		// additional styling for hover effect on thumbs

		$('#thumbs ul.thumbs li').opacityrollover({
			mouseOutOpacity:   0.67,
			mouseOverOpacity:  1.0,
			fadeSpeed:         'fast',
			exemptionSelector: '.selected'
		});

	
		$('#thumbs').galleriffic({
			delay:                     5000,
			autoStart:                 true,
			syncTransitions:       	   false,
			enableKeyboardNavigation:  false,
			defaultTransitionDuration: 800,
			imageContainerSel:         '#slideshow',
			onSlideChange:             function(prevIndex, nextIndex) {

				this.find('ul.thumbs').children().eq(prevIndex).fadeTo('fast', 0.67).end().eq(nextIndex).fadeTo('fast', 1.0);

			},
			onPageTransitionOut:       function(callback) {},
			onPageTransitionIn:        function() {}
		});
	}
	
    // Gestion accueil news slideShow
    if($('#thumbsNews').length) {
    	$("#thumbsNews").carousel({
    		loop: true
    	});
    }


	// Gestion du roll sur les pictos
    if($('#blocPicto').length) {
		$('#blocPicto img').hover(
			function(){
				var imgName = $(this).attr('src');
				var t = imgName.split('.');
				$(this).attr('src', t[0]+'-roll.png');
			},	
			function(){
				var imgName = $(this).attr('src');
				var t = imgName.split('-roll');
				$(this).attr('src', t[0]+'.png');
			}
		);
		
		$('#blocPicto img').eq(1).click(function(){
			$('#blocAvoirForm').fadeToggle('slow');
		});
    }
    
    // Gestion du toggle pour les témoignages
    if($('#blocToggle').length) {
    	
    	$('#blocToggle .ssBlocToggleBottom').hide();
    	
    	$('#blocToggle .ssBlocToggleTop').click(function () {
    		$(this).toggleClass('actif');
    		$(this).find('.fleche').toggleClass('actif');
    		$(this).next().slideToggle('slow');
        });

    }
    
    $('#webSite').hide();
    
    
});