$(document).ready(function() {

  // Show
  $('.showSwitch').click(function(event) {
    event.preventDefault();
    $(this).css('outline','none');
    var i = '1';
    while($(this).attr('target' + i))
    {
      var id = '#' + $(this).attr('target' + i);
      if (!$(id).hasClass("showSwitch_flag")) {
        $('.showSwitch_flag').fadeOut(1000, function(){
          $('.diaporama_chambre img').hide();
          $('.showSwitch_flag').removeClass('showSwitch_flag');
          $(id).fadeIn({
            duration: 1000
          });
          $(id).removeClass('hide');
          $(id).addClass('showSwitch_flag');
        });
      }
      i++;
    }
  });
  // Show
  window.setTimeout(function(){
    diaporama_chambre();
  }, 5000);

  // Show
  $('.diaporama img').each(function(event) {
    if(!$(this).hasClass('diaporama_flag'))
    {
      i = myBgs.length;
      myBgs[i] = $(this).attr('id');
    }
  });

  window.setTimeout(function(){
    diaporama(myBgs,0,myBgs.length, 'diapo_0', 2000);
  }, 1000);

  $('#ReservationNombrech').change(function(){
    var value = $('option:selected', this).attr('value');
    switch(value)
    {
      case '1':
        $('.chambre_2 div.input').hide();
        $('.chambre_3 div.input').hide();
      break;
      case '2':
        $('.chambre_2 div.input').show();
        $('.chambre_3 div.input').hide();
      break;
      case '3':
        $('.chambre_2 div.input').show();
        $('.chambre_3 div.input').show();
      break;
    }
  });
  // Calendrier
  initCalendrier();


  jQuery('#mycarousel').jcarousel({
    	wrap: 'circular'
    });
});

var myBgs = new Array();
function diaporama(myBgs,index,max, first, time)
{
  $('#' + myBgs[index]).fadeOut(time);
  if(index < max-1)
    index++;
  else
    index = 0;

  $('#' + myBgs[index]).fadeIn(time);
  $('#' + myBgs[index]).removeClass('hide');
  window.setTimeout(function(){
    diaporama(myBgs, index, max, false, time);
  }, 5000);

  if(first)
    window.setTimeout(function(){
      $('#' + first).addClass('hide');
    }, time);

}
function diaporama_chambre()
{
  var target;
  if($('.showSwitch_flag + img:first').length != 0)
    target = $('.showSwitch_flag + img:first');
  else
    target = $('.diaporama_chambre img:first');
  $('.showSwitch_flag').fadeOut(1000, function(){
    $('.diaporama_chambre img').hide();
    $(target).fadeIn(1000);
    $('.showSwitch_flag').removeClass('showSwitch_flag');
    $(target).addClass('showSwitch_flag');
  });

  window.setTimeout(function(){
    diaporama_chambre();
  }, 5000);

}
function initCalendrier(){
  $('.calBtn').click(function(event){
    event.preventDefault();
    var result = 'date=' + $(this).attr('date') + '&id=' + $('#chambreId').val();
      $.ajax({
        type: "POST",
        url: '../../../chambres/calendrier',
        data: result,
        beforeSend: function( xhr ) {
        },
        success: function(msg){
        $('#calendar').html(msg)
        initCalendrier();
        }
      });
  });
}




















