// Adjust thumbnail sizes to best fit a given box
// $('.some img').bestFit(100, 30)
(function($){
  $.fn.bestFit = function(max_w, max_h){
    function getWidth(w, h){
      return Math.floor((max_h * w) / h);
    };
    function getHeight(w, h){
      return Math.floor((max_w * h) / w);
    };
    return $(this).each(function(){
      var w = $(this).width(), h = $(this).height();
      if(w > h){ // horizontal
        $(this).css({width: max_w + 'px', height: getHeight(w, h) + 'px'});
      }else {//vertical
        $(this).css({width: getWidth(w, h) + 'px', height: max_h + 'px'});
      }
    });
  }
})(jQuery);

$(window).load(function(){
  // Resize thumbnails depending on orientation
  $('.js_gallery a img').bestFit(121, 180);
  // $('.bigimg img').bestFit(360, 375);
});
