var gap_width = 12;
var column_width = 144;

jQuery(function() {
  update_layout();
});

jQuery(window).resize(function(){
  jQuery('body').addClass('layout-ready');
  update_layout();
});

// var intervalID = window.setInterval(update_layout,200);

function update_layout() {
  /* horizontal alignment */
  var canvaswidth = jQuery(window).width();
  var columns_that_fit = Math.floor(canvaswidth / (column_width + gap_width + ((gap_width * 2))));
  var wrapper_width = (columns_that_fit * (column_width + gap_width));
  jQuery('#page-wrapper, #footer > .section').css({width:wrapper_width});
  /* jQuery('body').addClass('has_' + columns_that_fit + '_columns'); */


  /* vertical alignment */
  var pageheight = jQuery('#main-wrapper').height();
  var canvasheight = jQuery(document).height();
  if(canvasheight > pageheight) {
    var margintop = (canvasheight / 2) - (pageheight / 2);
    var header_height = jQuery('#header').height();
    jQuery('#header').css({paddingBottom:margintop - header_height});
  } else {
    jQuery('#header').css({paddingBottom:0});
  }
};

