jQuery(function($){

  $('.inventory').each(function(){
    var $buttons = $(this).find('a.units');
    var $links = $(this).find('a').not('.units');
    var $img = $(this).find('a.preview span');

    // Toggle units
    $buttons.click(function(event){
      event.preventDefault();
      $buttons.removeClass('active');
      $links.attr('href', $(event.target).attr('href'));

      // Do imperial stuff
      if ($(event.target).addClass('active').hasClass('imperial')){
        $img.animate({ left: '-'+($img.width()/2)+'px' });
      } else {
        $img.animate({ left: '0px' });
      }
    });

    $('a.units:first').click();
  });


});

