jQuery.noConflict();

jQuery(function($) {

  // Gestion du select exposants (recherche)
  jQuery(".selectTheme").change(function() {
    jQuery.post("/exposant/exposantListe", "theme=" + jQuery(this).val(), function(data) {
      jQuery(".selectExposants").html(data);
      jQuery(".selectExposants").removeAttr("disabled");
    });

  });

  // Gestion Google Map
  if($('#mapHotel').length) {
      initMap();
  }

  // Gestion Carousel Hotel
  function carouselHotel(carousel) {

      var height = 22;/*$('.carouselHotel li').height();*/
      var nombreItem = $('.carouselHotel li').length;
      var reference = referenceInit = 3;
      var animationActive = false;

      $('.down', carousel).click(function () {
          if(reference < nombreItem && animationActive == false) {
              animationActive = true;
              var deplacement = parseInt($('.carouselHotel ul').css('top').split('px')) - height;
              deplacement += 'px';
              $('.carouselHotel ul').animate({
                  top: deplacement
                  }, 200, function() { animationActive = false; }
              );
              reference++;
          }
          return false;
      });
      $('.up', carousel).click(function () {
          if(reference > referenceInit && animationActive == false) {
              animationActive = true;
              var deplacement = parseInt($('.carouselHotel ul').css('top').split('px')) + height;
              deplacement += 'px';
              $('.carouselHotel ul').animate({
                  top: deplacement
                  }, 200, function() { animationActive = false; }
              );
              reference--;
          }
          return false;
      });
  }
  carouselHotel('.carouselHotel');

  /**
   * carouselSelection : Permet de générer un nouveau carousel horizontal
   *
   * @author Eric Giovannetti       <eric@bleuroy.com>
   * @params string  _carousel      L'identifiant du carousel.
   * @params string  _itemDeplace   L'identifiant du bloc qui va se déplacer.
   * @params int     _itemsVisibles Nombre d'items visibles par défaut.
   * @params int     _vitesse       Vitesse de déplacement en millisecondes.
   * @params string  _boutons       Defini le type de boutons.
   * @params boolean _autoslide     Défini si l'autoslide est actif.
   * @version 1.3.0
   */

   function generateCarousel(_carousel, _itemDeplace, _itemsVisibles, _vitesseDeplacement, _boutons, _autoslide, _vitesse) {
       var width           = $(_carousel + ' ' + _itemDeplace + ' > *').width();
       var nombreItems     = $(_carousel + ' ' + _itemDeplace + ' > *').length;
       var widthTotal      = width * nombreItems;
       var reference       = _itemsVisibles;
       var referenceInit   = _itemsVisibles;
       var animationActive = false;

       $(_carousel + ' ' + _itemDeplace).css('width', widthTotal + 'px');

       if(nombreItems > _itemsVisibles) {

           if(_boutons == 'defilement') {


               $(_carousel).append('<div class="prev"><a href="#" title="Précédent"></a>');
               $(_carousel).prepend('<div class="next"><a href="#" title="Suivant"></a>');


               $(_carousel + ' .prev').click(function () {
                   if(reference > referenceInit && animationActive == false) {
                       animationActive = true;
                       var deplacement = parseInt($(_carousel + ' ' + _itemDeplace).css('left').split('px')) + width;
                       deplacement += 'px';
                       $(_carousel + ' ' + _itemDeplace).animate({
                           left: deplacement
                           }, _vitesseDeplacement, function() { animationActive = false; }
                       );
                       reference--;
                   }
                   return false;
               });

               $(_carousel + ' .next').click(function () {
                   if(reference < nombreItems && animationActive == false) {
                       animationActive = true;
                       var deplacement = parseInt($(_carousel + ' ' + _itemDeplace).css('left').split('px')) - width;
                       deplacement += 'px';
                       $(_carousel + ' ' + _itemDeplace).animate({
                           left: deplacement
                           }, _vitesseDeplacement, function() { animationActive = false; }
                       );
                       reference++;
                   }
                   return false;
               });

               if(_autoslide == true) {
                   var interval = false;
                   function intervalSlide() {
                       interval = setInterval(function() {
                           if(reference < nombreItems) {
                               $(_carousel + ' .next').click();
                           } else {
                               reference = referenceInit;
                               $(_carousel + ' ' + _itemDeplace).animate({
                                   left: '0px'
                                   }, _vitesseDeplacement, function() { animationActive = false; }
                               );
                           }
                       }, 3000);
                   }
                   intervalSlide();
                   $(_carousel).bind('mouseover', function(){ clearInterval(interval); });
                   $(_carousel).bind('mouseout', function(){ intervalSlide(); });
               }

           } else if(_boutons == 'numerotation') {

               var nombreCases = nombreItems/_itemsVisibles;
               var items = '<div class="numerotation">';
               for(var i = 0; i < nombreCases; i++) {
                   items += '<a href="#" class="item'+i+'">'+(i+1)+'</a> ';
               }
               items += '</div>';
               $(_carousel).prepend(items);
               $(_carousel + ' .numerotation a:eq(0)').addClass('actif');

               $(_carousel + ' .numerotation a').click(function () {
                   $(_carousel + ' .numerotation a.actif').removeClass('actif');
                   var item = $(this).attr('class').split('item');
                   $(this).addClass('actif');
                   var deplacement = -(item[1] * width);
                   deplacement += 'px';
                   $(_carousel + ' ' + _itemDeplace).animate({
                       left: deplacement
                       }, _vitesseDeplacement
                   );
                   return false;
               });

               if(_autoslide == true) {
                   var interval = false;
                   function intervalSlide() {
                       interval = setInterval(function() {
                           var afterActif = $(_carousel + ' .numerotation a.actif').next();
                           if(afterActif.length == true) {
                               afterActif.click();
                           } else {
                               $(_carousel + ' .numerotation a:eq(0)').click();
                           }
                       }, 3000);
                   }
                   intervalSlide();
                   $(_carousel).bind('mouseover', function(){ clearInterval(interval); });
                   $(_carousel).bind('mouseout', function(){ intervalSlide(); });
               }

           }

       }

   } /* Fin generateCarousel() */


   if ($('#carouselSelection').length > 0) {
       generateCarousel('#carouselSelection', 'ul', 3, 500, 'defilement', false);
   }

   $('#carouselSelection .masque a').click(function () {
       var nomImage = $(this).find('img').attr("src");
       nomImage = nomImage.replace(/mini/,"grande");
       $('.imgPhototheque img').attr('src', nomImage);
       $("#carouselSelection .masque a").removeClass("actif");
       $(this).addClass("actif");
       return false;
   });


   // Champ caché anti-spam
   $('input#anti').css('display', 'none');

}); /* jQuery end */
