$(document).ready(function(){

	$('.smoothscroll').live('click',function(e){
		$('html,body').animate({'scrollTop': $($(this).attr('href')).offset().top+'px'});
		e.preventDefault();	
	});

	  // set up lightboxes
  $('a.lbox').lightBox();

  /*
  $('#mycarousel').jcarousel({
    auto: 8,
    wrap: 'both',
    initCallback: mycarousel_initCallback,
    scroll: 1,
    itemVisibleInCallback: {
      onAfterAnimation: function(c, o, i, s) {
      --i;
       $('.jcarousel-control a').removeClass('selected');
       $('.jcarousel-control a:eq('+i+')').addClass('selected');
      }
    }
  });
  */


  $('.checkAvailability').click(function(e){
    $('#calendar_pane').html('<p>Loading..</p>');
    $('#calendar_pane').load('/book-online/load-calendar/', $('#book_online_form').serialize());
    e.preventDefault();
  });

  $('#book_online_form').change(function(e){
    $('#calendar_pane').html('<p>Please select your required month and year, and check our availability.</p>');
    e.preventDefault();
  });
  
  
  $('.book_ferry').change(function(e){
    if($('#booking_book_ferry_0').is(':checked')){
      // hide it
      $('#ferry_info').slideUp('fast');
      $('#no_ferry_info').slideDown('normal');
    }else{
      // show it
      $('#ferry_info').slideDown('normal');
      $('#no_ferry_info').slideUp('fast');
    }
  });
  if($('#booking_book_ferry_0')){
    if($('#booking_book_ferry_0').is(':checked')){      
      $('#ferry_info').hide();
      $('#no_ferry_info').show();
    }else{
      $('#no_ferry_info').hide();     
    }
  }
  
  
  setInterval( "slideSwitch()", 5000 );

});
	



// carousel thing
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();
    });

    jQuery('.jcarousel-control a').bind('click', function() {
        carousel.scroll(jQuery.jcarousel.intval(jQuery(this).text()));
        return false;
    });

  
  

};


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');
        });
}

