$().ready(function() {

  setInterval( "slideSwitch()", 5000 );
  
  $('#coda-slider-1').codaSlider();


  $(function(){
    $("#adultsUp").click(function(){
      $("#adults").val( Number($("#adults").val()) + 1 );
    });
    $("#adultsDown").click(function(){
      if($("#adults").val() > 0){
        $("#adults").val( Number($("#adults").val()) - 1 );
      }
    });
  });

  $(function(){
    $("#childrenUp").click(function(){
      $("#children").val( Number($("#children").val()) + 1 );
    });
    $("#childrenDown").click(function(){
      if($("#children").val() > 0){
        $("#children").val( Number($("#children").val()) - 1 );
      }
    });
  });


  $(function() {
    $("#check-in").datepicker({
      minDate: 0,
      showAnim: 'fadeIn',
      showOn: 'both',
      buttonImage: 'img/gui/calendarIcon.gif',
      buttonImageOnly: true,
      dateFormat: 'mm/dd/yy',
      onSelect: function(dateStr) {
        var date = $(this).datepicker('getDate');
        if (date) {
          date.setDate(date.getDate() + 1);
          $("#check-out").datepicker("option", "minDate", date);
        }
      }
    });

    $("#check-out").datepicker({
      showAnim: 'fadeIn',
      showOn: 'both',
      buttonImage: 'img/gui/calendarIcon.gif',
      buttonImageOnly: true,
      dateFormat: 'mm/dd/yy'
    });
  });


});


  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');
        });
  }

