$(document).ready(function() {

  // set up lightboxes
  $('a.lbox').lightBox();
  
  $('#mycarousel_a').jcarousel({
    auto: 5,
    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');
      }
    }
  });
  
  $('#mycarousel_b').bxCarousel({
    display_num: 4,
    move: 2,
    prev_image: '/images/bx-prev.gif',
    next_image: '/images/bx-next.gif',
    margin: 20
  });

  $('.pagination-field').change(function(){
    $('#pagination_form').submit();
  });

  $('#deliver_to_billing_address').live('click', function(){
    if($(this).is(':checked')){
      $('#deliver_address_container').slideUp('fast');
    }else{
      $('#deliver_address_container').slideDown('fast');
    }
  });



  $('#add_to_basket_form').change(function(e){
  
    // load spinner.
    $('#prices').html('Loading Prices..');
  
    $('#prices').load('/shop/price-update/', $('#add_to_basket_form').serialize());
    
  });


});

// 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;
    });

};
