// =======================================
// = Appel de scripts et fonctions perso =
// =======================================

// On cache le contenu des tabs au chargement de la page
jQuery(document).ready(function() {
  jQuery('.left-bloc-slide-right-texte').hide();
});


//------------------- Tabs (homepage)
jQuery(document).ready(function() {
  var currentPage = jQuery('.actif').index();
  jQuery('.left-bloc-slide-right-image img').eq(currentPage).show();
  jQuery('.left-bloc-slide-right-texte').eq(currentPage).show();
  jQuery('.left-bloc-slide-left li').hover(function() {
    var currentNumber = jQuery(this).index();
    jQuery(this).addClass('hover');
    jQuery('.left-bloc-slide-left li').removeClass('actif');
    jQuery('.left-bloc-slide-right-image img').eq(currentNumber).show().siblings().hide();
    jQuery('.left-bloc-slide-right-texte').eq(currentNumber).show().siblings('.left-bloc-slide-right-texte').hide();
  }, function() {
    jQuery(this).removeClass('hover');
    jQuery('.left-bloc-slide-left li').eq(currentPage).addClass('actif');
    jQuery('.left-bloc-slide-right-image img').eq(currentPage).show().siblings().hide();
    jQuery('.left-bloc-slide-right-texte').eq(currentPage).show().siblings('.left-bloc-slide-right-texte').hide();
  });
  jQuery('.left-bloc-slide-left li').click(function() {
    jQuery(this).addClass('actif');
    currentPage = jQuery('.actif').index();
    return false;
  });
});


//-------------------- Variation d'opacité sur la page de références
jQuery(function(){
  // jQuery('#listingReferences li a.box').show();
  var onMouseOutOpacity = 0.4;

  jQuery('#listingReferences a.box img').css('opacity', onMouseOutOpacity)
  .hover(
    function () {
      jQuery(this).fadeTo('fast', 1.0);
    }, 
    function () {
      jQuery(this).fadeTo('fast', onMouseOutOpacity);
    } 
  );  
 
});

//----------------------- slideshow sur la homepage
jQuery(function () {
  jQuery('.anythingSlider').anythingSlider({
    easing: "easeInOutExpo",
    autoPlay: true,
    delay: 4000,
    startStopped: false,
    animationTime: 800,
    hashTags: false,
    buildNavigation: false,
    pauseOnHover: true,
    startText: "",
    stopText: "",
    navigationFormatter: null
  });
});



// ----------------------------Fonction pour que les scripts de scroll se figent au hover
function mycarousel_initCallback(carousel)
{
  // Disable autoscrolling if the user clicks the prev or next button.
  carousel.buttonNext.bind('click', function() {
    carousel.startAuto(0);
  });
  carousel.buttonPrev.bind('click', function() {
    carousel.startAuto(0);
  });
  // Pause autoscrolling if the user moves with the cursor over the clip.
  carousel.clip.hover(function() {
    carousel.stopAuto();
  }, function() {
    carousel.startAuto();
  });
};

// ----------------------------Scroll horizontal en homepage
jQuery(document).ready(function() {
    jQuery('#mycarousel').jcarousel({
        auto: 2,
        scroll: 1,
        wrap: 'last',
        buttonNextHTML: '',
        buttonPrevHTML: '',
        visible: 8,
        initCallback: mycarousel_initCallback
    });
});

// ----------------------------Varation d'opacité sur les images du scroll horizontal en homepage
jQuery(document).ready(function() {
  jQuery('.jcarousel-skin-homepageTop .jcarousel-item').hover(function() {
    jQuery(".couleur", this).fadeIn('400');
  }, function() {
    jQuery(".couleur", this).fadeOut('fast');
  });
});


// -----------------------------Fancybox sur la page de référence
jQuery(document).ready(function() {
  jQuery('#listingReferences li a.box').fancybox();
});


// ----------------------------Mini scroll dans la sidebar
jQuery(document).ready(function() {
    jQuery('#sideCarousel').jcarousel({
        auto: 3,
        scroll: 1,
        wrap: 'last',
        buttonNextHTML: '',
        buttonPrevHTML: '',
        initCallback: mycarousel_initCallback
    });
});

// ------------------------centrage des images
jQuery(document).ready(function() {
  var widthContainer = jQuery('.jcarousel-item').width();
  var heightContainer = jQuery('.jcarousel-item').height();
  jQuery('.jcarousel-skin-homepageTop .jcarousel-item img').each(function(index) {
    var widthImg = jQuery(this).attr('width');
    var heightImg = jQuery(this).attr('height');
    var marginImgLeft = (widthContainer/2) - (widthImg/2);
    var marginImgTop = (heightContainer/2) - (heightImg/2);
    jQuery(this).css('left', marginImgLeft);
    jQuery(this).css('top', marginImgTop);
  });
  
});

