var FontSize = {
  SCALE_FACTOR: .2,
  DEFAULT_SCALE: '70%',
  MAX_LEVEL: 2,

  initial: null,
  unit: null,
  level: 0,

  decrease: function() { FontSize.scale(-1); },
  increase: function() { FontSize.scale(1); },
  
  scale: function(factor) {
    if (FontSize.level + factor > FontSize.MAX_LEVEL || FontSize.level + factor < -FontSize.MAX_LEVEL) {
      return;
    }

    FontSize.level += factor;

    if (FontSize.initial == null) {
      var size = document.body.style.fontSize || FontSize.DEFAULT_SCALE;
      FontSize.unit = size.replace(/^[\d.]+([^\d]+)$/, '$1');
      FontSize.initial = parseFloat(size.replace(/[^\d.]/, ''));
    }

    document.body.style.fontSize = (FontSize.initial * (1 + FontSize.level * FontSize.SCALE_FACTOR)) + FontSize.unit;
    
    FontSize.updateButtons();
  },
  
  updateButtons: function() {
    document.getElementById('fontadjust-decrease').className = FontSize.level <= -FontSize.MAX_LEVEL ? 'disabled' : '';
    document.getElementById('fontadjust-increase').className = FontSize.level >= FontSize.MAX_LEVEL ? 'disabled' : '';
  }
};