Cufon.replace('.form-label label');

$.preLoadImages(
  themeurl + '/images/btn-update-active.png'
);

jQuery(document).ready(function($){
  
  $('.form-field input, .form-field select, .form-field textarea').blur(function(){
    $(this).removeClass('active');
  }).focus(function(){
     $(this).addClass('active');
  });
  
  var updateShippingOnBillingChange = function(){
    $('#shippingSameBilling').click().click();
  }
  
  var disableSelect = function(e){
    e.preventDefault();
  }
    
  var disableOrEnable = function(els, dis){
    if(undefined === dis){
      dis = true;
    }
    if(dis === true){  
      $(els).attr('readonly', 'readonly').addClass('disabled');
       $('.wpsc_checkout_table.billing :input').livequery('change', updateShippingOnBillingChange);   
       $('.wpsc_checkout_table.shipping select').bind('focus', disableSelect);
    } else {
      $(els).removeAttr('readonly').removeClass('disabled');
      $('.wpsc_checkout_table.billing :input').expire('change', updateShippingOnBillingChange);
       $('.wpsc_checkout_table.shipping select').expire('click', disableSelect);
    }
  }
  

  
  $('#shippingSameBilling').bind('change', function(){
    var shipping_inputs = $('.wpsc_checkout_table.shipping :input').not('#shippingSameBilling');
    if($(this).is(':checked')){
      //hide
      disableOrEnable(shipping_inputs);
    } else {
      //show
       disableOrEnable(shipping_inputs, false);
    }
  });
  
  if($('#shippingSameBilling').is(':checked')){
    var shipping_inputs = $('.wpsc_checkout_table.shipping :input').not('#shippingSameBilling');
    disableOrEnable(shipping_inputs);
    updateShippingOnBillingChange();
  }
  
  /** Buttons Hovers **/
  $('button').hover(function(){
    $(this).addClass('active');
  }, function(){
    $(this).removeClass('active');
  });
  
  /** Tos **/
  $('.tos-show').click(function(e){
    $('#tos_content').toggle('fast');
    e.preventDefault();
  });
  
  
});