jQuery(window).load(function () {
   var $ = jQuery;

   ///////////////

   var scaleBoxes = $('.imagebox');

   scaleBoxes.each(function () {
      var box = $(this);
      var img = $('img', this);

      var offset = 0;

      /////////

      aspect_box = box.width() / box.height();
      aspect_img = img.width() / img.height();

      if (isNaN(aspect_img)) {
         return;
      }

      //fix landscape images
      if (aspect_img > aspect_box) {
         offset = Math.floor(box.height() - img.height()) / 2;

         img.css({top: offset});
      }
   });
});


