$(document).ready(function(){
  
  // original image size / ratio
  var imgWidth  = $( 'img.background' ).width();
  var imgHeight = $( 'img.background' ).height();
  var imgRatio  = imgWidth / imgHeight;
  
  function fitAll( ) {
    // new screen size / ratio
    var navWidth  = $(window).width();
    var navHeight = $(window).height();
    var navRatio  = navWidth / navHeight;
    
    // sets background image size
    if ( navRatio > imgRatio ) {
      $( 'img.background' ).width( navWidth );
      $( 'img.background' ).height( navWidth / imgRatio );
    } else {
      $( 'img.background' ).width( navHeight * imgRatio );
      $( 'img.background' ).height( navHeight );
    }
    
    if ( navWidth > 965 ) {
      $( 'div.page-bg' ).css({ left: ( ( navWidth - 965 ) / 2 ) + 3 });
    } else {
      $( 'div.page-bg' ).css({ left: 3 });
    }
    
    /*
    if ( $( 'div.content' ).height() < navHeight ) {
      $( 'div.content' ).height( navHeight );
    }
    */
    
    if ( ( $( 'div.content-text' ).height() + $( 'div.content-top' ).height() + $( 'div.links' ).outerHeight() ) < navHeight ) {
      $( 'div.content-text' ).height( navHeight - ( $( 'div.content-top' ).height() + $( 'div.links' ).outerHeight() ) );
    }
    
  }
  
  fitAll( );
  
  $(window).resize(function(){
    fitAll( );
  });
});
