Let's take this opportunity to make this better.  I worry now that the current code will not work right for devices that are close to square.  It could be that on some devices thumbnails will be wider in portrait mode than in landscape mode.  How about something like this:

function computeThumbnailWidth() {
  // Make sure this works regardless of current device orientation
  var portraitWidth = Math.min(window.innerWidth, window.innerHeight);
  var landscapeWidth = Math.max(window.innerWidth, window.innerHeight);
  var thumbnailsPerRowPortait = isPhone ? 3 : 4;
  var thumbnailsPerRowLandscape = isPhone ? 4 : 6;
  return Math.round(Math.max(portraitWidth/thumbnailsPerRowPortrait, landscapeWidth/thumbnailsPerRowLandscape));
}