function show_checkout_password_field() {
    if($('input[type=radio][name=customer][value=returning]').is(':checked'))
      $('#checkout_password').fadeIn();
    else
      $('#checkout_password').fadeOut();
}
$('document').ready(function() {

  // Basket less/more qty buttons
  $('a.change_qty').click(function() {


    var variation_id = $(this).attr('id').split('_')[1];
    var input_field  = $('input#qty_' + variation_id);
    var qty          = parseInt(input_field.val(), 10);

    // Ensure not less than 0
    if($(this).hasClass('less'))
      input_field.val( (qty-1) < 0 ? 0 : qty-1 );

    if($(this).hasClass('more'))
      input_field.val(qty+1);

    return false;
  })

  // Quantity fields - select on focus
  $('input.qty').focus(function() {
    $(this).trigger('select');
  })

  // Autosubmit fields
  $('.autosubmit').change(function() {
    $(this).parents('form').trigger('submit');
  })
  
  
  // Giftwrap message
  if(!$('input[name=gift_wrapping]').is(':checked'))
    $('div.giftwrap_message').hide();
  $('input[name=gift_wrapping]').change(function() {
    if($(this).is(':checked')) {
      $('div.giftwrap_message').fadeIn();
      $('div.giftwrap_message textarea').focus();
    }
    else
      $('div.giftwrap_message').fadeOut();
  })
  
  // Make password disappear unless they say they are returning
  $('#checkout_password').hide();
  show_checkout_password_field()
  $('input[type=radio][name=customer]').live('change', show_checkout_password_field);

})
