

/*** 
    Simple jQuery Slideshow Script
    Released by Jon Raasch (jonraasch.com) under FreeBSD license: free to use or modify, not responsible for anything, etc.  Please link out to me if you like it :)
***/

function slideSwitch() {
	var $active = $('#slideshow IMG.active');

    if ( $active.length == 0 ) $active = $('#slideshow IMG:last');

    // use this to pull the images in the order they appear in the markup
    var $next =  $active.next().length ? $active.next() : $('#slideshow IMG:first');

    // uncomment the 3 lines below to pull the images in random order
    
    // var $sibs  = $active.siblings();
    // var rndNum = Math.floor(Math.random() * $sibs.length );
    // var $next  = $( $sibs[ rndNum ] );


    $active.addClass('last-active');
    
    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
         $active.removeClass('active last-active');
        });
}
/**
Jcaroussel control
 */





/**
Nice select http://tutorialzine.com/2010/11/better-select-jquery-css3/ */
/*
$(document).ready(function(){
	
	// The select element to be replaced:
	var select = $('select.makeMeFancy');

	var selectBoxContainer = $('<div>',{
		width		: select.outerWidth(),
		className	: 'tzSelect',
		html		: '<div class="selectBox"></div>'
	});

	var dropDown = $('<ul>',{className:'dropDown'});
	var selectBox = selectBoxContainer.find('.selectBox');
	
	// Looping though the options of the original select element
	
	select.find('option').each(function(i){
		var option = $(this);
		
		if(i==select.attr('selectedIndex')){
			selectBox.html(option.text());
		}
		
		// As of jQuery 1.4.3 we can access HTML5 
		// data attributes with the data() method.
		
		if(option.data('skip')){
			return true;
		}
		
		// Creating a dropdown item according to the
		// data-icon and data-html-text HTML5 attributes:
		
		var li = $('<li>',{
			html:	'<span>'+
					option.data('html-text')+'</span>'
		});
				
		li.click(function(){
			
			selectBox.html(option.text());
			dropDown.trigger('hide');
			
			// When a click occurs, we are also reflecting
			// the change on the original select element:
			select.val(option.val());
			
			return false;
		});
		
		dropDown.append(li);
	});
	
	selectBoxContainer.append(dropDown.hide());
	select.hide().after(selectBoxContainer);
	
	// Binding custom show and hide events on the dropDown:
	
	dropDown.bind('show',function(){
		
		if(dropDown.is(':animated')){
			return false;
		}
		
		selectBox.addClass('expanded');
		dropDown.slideDown();
		
	}).bind('hide',function(){
		
		if(dropDown.is(':animated')){
			return false;
		}
		
		selectBox.removeClass('expanded');
		dropDown.slideUp();
		
	}).bind('toggle',function(){
		if(selectBox.hasClass('expanded')){
			dropDown.trigger('hide');
		}
		else dropDown.trigger('show');
	});
	
	selectBox.click(function(){
		dropDown.trigger('toggle');
		return false;
	});

	// If we click anywhere on the page, while the
	// dropdown is shown, it is going to be hidden:
	
	$(document).click(function(){
		dropDown.trigger('hide');
	});
});
*/
/**
Nice select http://tutorialzine.com/2010/11/better-select-jquery-css3/ */
/*
$(document).ready(function(){
	
	// The select element to be replaced:
	var select = $('select.makeMeFancy2');

	var selectBoxContainer = $('<div>',{
		width		: select.outerWidth(),
		className	: 'tzSelect',
		html		: '<div class="selectBox"></div>'
	});

	var dropDown = $('<ul>',{className:'dropDown'});
	var selectBox = selectBoxContainer.find('.selectBox');
	
	// Looping though the options of the original select element
	
	select.find('option').each(function(i){
		var option = $(this);
		
		if(i==select.attr('selectedIndex')){
			selectBox.html(option.text());
		}
		
		// As of jQuery 1.4.3 we can access HTML5 
		// data attributes with the data() method.
		
		if(option.data('skip')){
			return true;
		}
		
		// Creating a dropdown item according to the
		// data-icon and data-html-text HTML5 attributes:
		
		var li = $('<li>',{
			html:	'<span>'+
					option.data('html-text')+'</span>'
		});
				
		li.click(function(){
			
			selectBox.html(option.text());
			dropDown.trigger('hide');
			
			// When a click occurs, we are also reflecting
			// the change on the original select element:
			select.val(option.val());
			
			return false;
		});
		
		dropDown.append(li);
	});
	
	selectBoxContainer.append(dropDown.hide());
	select.hide().after(selectBoxContainer);
	
	// Binding custom show and hide events on the dropDown:
	
	dropDown.bind('show',function(){
		
		if(dropDown.is(':animated')){
			return false;
		}
		
		selectBox.addClass('expanded');
		dropDown.slideDown();
		
	}).bind('hide',function(){
		
		if(dropDown.is(':animated')){
			return false;
		}
		
		selectBox.removeClass('expanded');
		dropDown.slideUp();
		
	}).bind('toggle',function(){
		if(selectBox.hasClass('expanded')){
			dropDown.trigger('hide');
		}
		else dropDown.trigger('show');
	});
	
	selectBox.click(function(){
		dropDown.trigger('toggle');
		return false;
	});

	// If we click anywhere on the page, while the
	// dropdown is shown, it is going to be hidden:
	
	$(document).click(function(){
		dropDown.trigger('hide');
	});
});
*/
//-------------------------------------------------------------------------------- JS ajout interrupteur js sur body
$(function() {$("body").addClass("js");})

	//---------------------------------------------------------------------------- Init accordion
$(function() {
	$('.accordion h2').click(function() {
			
			var isCurrent = $(this).next().is(".deploi")
			
			$(".accordion .deploi").slideUp('slow');
			$(".accordion .deploi").removeClass('deploi'); //-----syb
			$(".accordion h2").removeClass('active');
			
			if (!isCurrent)
				{
				$(this).next().slideDown('slow');
				$(this).next().addClass('deploi'); //-----syb
				$(this).addClass('active');
				}	
			
			return false;
		})
});

//------------------------------------------------------------------------------ Carousel-control behaviour
$(function() {
	var currentBlock = 0
	var blockMax = $(".jcarousel-list li").length - 1
	
	$("#mycarousel").jcarousel({
		scroll: 1,
		initCallback: mycarousel_initCallback,
		// This tells jCarousel NOT to autobuild prev/next buttons
		buttonNextHTML: null,
		buttonPrevHTML: null
	});
	
	$('#slideshow IMG:first').addClass("active");
	$(".jcarousel-control a.jcarousel-control-1").addClass("first");
	$("#mycarousel-prev").css('visibility','hidden')
	
	$("#mycarousel-next").click(function()
		{
		currentBlock = (currentBlock<blockMax) ? currentBlock + 1 :blockMax;
		$("#mycarousel-next").css('visibility',(currentBlock < blockMax) ? 'visible':'hidden')
		$("#mycarousel-prev").css('visibility',(currentBlock > 0) ? 'visible':'hidden')
		}
	)
	
	$("#mycarousel-prev").click(function()
		{
		currentBlock = (currentBlock>0) ? currentBlock - 1:0;
		$("#mycarousel-prev").css('visibility',(currentBlock > 0) ? 'visible':'hidden')
		$("#mycarousel-next").css('visibility',(currentBlock < blockMax) ? 'visible':'hidden')
		}
	)
	
	$(".jcarousel-control a").click(function() {
		currentBlock = Number(this.innerText)-1
		$("#mycarousel-prev").css('visibility',(currentBlock > 0) ? 'visible':'hidden')
		$("#mycarousel-next").css('visibility',(currentBlock < blockMax) ? 'visible':'hidden')
	});

	$(".jcarousel-scroll a").click(function() {
		var $active = $('#slideshow IMG.active');
		if ( $active.length == 0 ) $active = $('#slideshow IMG:last');
		// use this to pull the images in the order they appear in the markup
		var $next =  $active.next().length ? $active.next(): $('#slideshow IMG:first');
		
		$active.addClass('last-active');
		
		
		if (jQuery.support.opacity) {
		    $next.css('opacity', '0.0').addClass('active');
			$next.animate({opacity: 1.0}, 1000, function() {$active.removeClass('active last-active');});
		} else {
		    $next.css('filter', 'alpha(opacity=1)').addClass('active');
			$next.animate({filter: 'alpha(opacity=100)'}, 1000, function() {$active.removeClass('active last-active');});
		}
		

	});
})

/** edito.html declenchement fade image lors du clic sur bouton caroussel/ */

function mycarousel_initCallback(carousel) {
    jQuery('.jcarousel-control a').bind('click', function() {
        carousel.scroll(jQuery.jcarousel.intval(jQuery(this).text()));
			$(".jcarousel-control a").removeClass("active");
			$(this).addClass("active");

        return false;
    });

    jQuery('#mycarousel-next').bind('click', function() {
        carousel.next();
        return false;
    });

    jQuery('#mycarousel-prev').bind('click', function() {
        carousel.prev();
        return false;
    });
};
$(".jcarousel-scroll a").click(function() {
	$(".jcarousel-control a.jcarousel-control-1").removeClass("first");
});

jQuery("#mycarousel").jcarousel({
        scroll: 1,
        initCallback: mycarousel_initCallback,
        // This tells jCarousel NOT to autobuild prev/next buttons
        buttonNextHTML: null,
        buttonPrevHTML: null,
        itemVisibleInCallback: {
            onAfterAnimation: function(c, o, i, s) {
            --i;
              jQuery('.jcarousel-control a').removeClass('active').addClass('inactive');
              jQuery('.jcarousel-control a:eq('+i+')').removeClass('inactive').addClass('active');
            }
          }
    });
