function resizeImage() {
  var windowWidth = $(window).width();
  var windowHeight = $(window).height();
  var windowAspect = windowWidth / windowHeight;
      
  $('#imagebg').css({'width':windowWidth, 'height':windowHeight});

  var img = $('#imagebg img');
  var oldWidth = img.width();
  var oldHeight = img.height();
  var aspect = oldWidth / oldHeight;
  
  if ( windowWidth > windowHeight && windowAspect >= aspect ) {
    img.width(windowWidth);
    var factor = windowWidth / oldWidth;
    img.height(Math.ceil(oldHeight * factor));
  } else {
    img.height(windowHeight);
    var factor = windowHeight / oldHeight;
    img.width(Math.ceil(oldWidth * factor));
  }

}
