/* Control page overflow for fixed-sized-and-centered sites.
 * ----------------------------------------------------------------------------
 *
 * Copyright (C) 2009 Raphaël Bois.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to
 * deal in the Software without restriction, including without limitation the
 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 * sell copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 * IN THE SOFTWARE.
 *
 * ----------------------------------------------------------------------------
 * page-overflow.js
 */

/*var siteWidth = -1;
var siteHeight = -1;*/
(function ($) {
var resizeCb = function () {
  var c = $('#contener');
  var width = c.width();
  var height = c.height();
  var win = $(window);
  var winWidth = win.width();
  var winHeight = win.height();
  var classes;
  var resize = true;
  var r;

  if (winWidth < width) {
    classes = 'hleft';
    resize = false;
  } else {
    classes = 'hcenter';
  }
  if (winHeight < height) {
    classes += ' vtop';
    resize = false;
  } else {
    classes += ' vcenter';
  }
  
  r = resize ? parseInt(98 * Math.min((1.0*winHeight)/height, (1.0*winWidth)/width, 1.4)) : 100;
  r = Math.max(100, r);
  $('body').css('zoom', ''+r+'%');

  c.attr('class', classes);
}

$(resizeCb);
$(window).resize(resizeCb);

/*
var checkPageOverflow = function (page_id) {
  var page = document.getElementById(page_id);
  var classes = "";
  var width, height;
  if (!page) { return; }
  try {
    width = window.body.offsetWidth;
    height = window.body.offsetHeight;
  } catch (e) {
    try {
      width = window.innerWidth;
      height = window.innerHeight;
    } catch (e) {
      return;
    }
  }
  var resize = true;
  if (width < siteWidth) {
    classes = "hleft";
    resize = false;
  } else {
    classes = "hcenter";
  }
  if (height < siteHeight) {
    classes += " vtop";
    resize = false;
  } else {
    classes += " vcenter";
  }
  if (resize) {
    var ry = height / siteHeight;
    var rx = width / siteWidth;
    var r = parseInt(100 * Math.min(ry, rx, 1.4));
    $('body').css('zoom', ''+r+'%');
  } else {
    $('body').css('zoom', '100%');
  }
  page.className = classes;
}

var _f=function(){checkPageOverflow('contener');};
$(_f);
$(window).resize(_f);
*/
})(jQuery);

