(function($){
//addclass
  function addclass() {
    $('.content > div:first-child').addClass('net');
    $('img:nth-child(2)').parent('p').addClass('slider');
    $(".slider img").wrap("<div></>")
  };

//functionsscroll
  function scrollbar() {
    var $colum = $(".column:not('#recherche-artistique'), #recherche-artistique > div");

    $(window).on("load",function(){
      $colum.mCustomScrollbar({
        theme:"minimal",
        mouseWheelPixels: 200,
        scrollInertia: 1000,
      });
    });
  };

  function scrollW() {
      $('a[href^="#"]').on('click', function(evt){
         evt.preventDefault();
         var target = $(this).attr('href');
         var rclass = $('.net');
         $('.underline').removeClass('underline');
         $(this).parent().addClass('underline');

         $('.block').removeClass('block');
         $('.sous-menu .underline').parent().addClass('block');

         $(rclass).removeClass('net');
         $(target).addClass('net');

         $(' html, body')
          .stop()
          .animate({
            scrollLeft: $(target).offset().left - ( $('section > div').width() - $('section > div').outerWidth() + $('header').outerWidth() ) },1000, );
      });
  };

  //mediaquieries

  function scrollTop(){

    $('a[href^="#"]').on('click', function(evt){
       evt.preventDefault();
       var target = $(this).attr('href');
       var rclass = $('.net');

       $('.underline').removeClass('underline');
       $(this).parent().addClass('underline');

       $('.block').removeClass('block');
       $('.sous-menu .underline').parent().addClass('block');

       $(rclass).removeClass('net');
       $(target).addClass('net');

      $('html,body').animate({
          scrollTop: $(target).offset().top - $('header').outerHeight()},'slow');
        });
  }

function clickd() {
  var $rclass = $('.net');

  $('.content > div:not(#recherche-artistique), #recherche-artistique > div ').on('click', function(e) {

    $rclass.removeClass('net');
    $(this).addClass('net');

    $(' html, body').stop().animate({
       scrollLeft: $(this).offset().left - ( $('section > div').width() - $('section > div').outerWidth() + $('header').outerWidth() ) },1000);
  });
};

  function gallery() {
    $('.slider').bxSlider({
      mode: 'horizontal',
      captions: true,
      adaptiveHeight:true,
      slideWidth: 600,
      touchEnabled: true,
      responsive:true,
      preloadImages: 'visible',
      touchEnabled: false,
      pager: false,
    });
  };

  function Openfp() {
    var $divgal = $( "<div id='gallery'></div>");
    var $button = $( "<button class=button></button>");
    var $img = $("img")

    $img.each(function(index) {

        $(this).on("click", function() {

            $('body').prepend( $divgal );
            $(this).clone().appendTo('#gallery');
            $('#gallery').fadeIn(400).prepend( $button );
            $('#gallery > img').wrap('<div class=content-img style=opacity:1></div>');

        $( '#gallery' ).click(function(e) {
          $(' #gallery, #gallery > .content-img').fadeOut(400, function() {
            $(this).remove();
          });
        });
      });
    });
  };

  function liclick() {
    var $ulf = $('section #recherche-artistique #commentaire-philosophe ul > li > p')
    var $olf = $('section #recherche-artistique #commentaire-philosophe ul > li > ol > li')
    var $mark = $('section #recherche-artistique #commentaire-philosophe ul > li > ol')

    $ulf.nextAll('ol').hide();
    $('#commentaire-philosophe ul > li:nth-child(1) ol').show();

    $mark.parent().children('p').css("text-decoration","underline");

    $ulf.on("click", function(event) {
      $(this).nextAll('ol').toggle(function() {
        $(this).css({
          "max-height" : "0",
          "opacity" : "0",
          "margin-left" : "0",
        });
      }, function() {
        $(this).css({
          "max-height" : "auto",
          "opacity" : "1",
          "margin-left" : "30px",
        });
      });
    });
  };

  function openmenu_ui() {
    $('.menu-ui').on("click", function(event) {
      $('.navigation').slideToggle('slow');
    });

    $('section').on("click", function(event) {
      $('.navigation').slideUp('slow');
    });
  };

  function redimensionnement() {
    var result = document.getElementById('result');
    if("matchMedia" in window) { // Détection
      if(window.matchMedia("(min-width: 955px)").matches) {
        scrollbar();
        scrollW();
        clickd();
      } else {
        scrollTop();
      }
    }
  }

  $(document).ready(function(){
    addclass();
    gallery();
    Openfp();
    liclick();
    openmenu_ui();
    redimensionnement();
    window.addEventListener('resize', redimensionnement, false);
  });

})(jQuery);
