
FontChanger = Class.create();
FontChanger.prototype = {
  id: null,
  cookieManager: null,
  cookieName: 'body.style.fontSize',
  initialize: function(id) {
    this.id = id || 'fontChanger';
    this.cookieManager = new CookieManager();
    var fontSize = this.cookieManager.getCookie(this.cookieName);
    if (fontSize) document.body.style.fontSize = fontSize;
  },
  setCookieShelfLife: function(days) {
    this.cookieManager.cookieShelfLife = days;
  },
  change: function(fontSize) {
    document.body.style.fontSize = fontSize;
    this.cookieManager.setCookie(this.cookieName, fontSize);
  },
  reset: function() {
    document.body.style.fontSize = '';
    this.cookieManager.clearCookie(this.cookieName);
  },
  show: function() {
    var id = this.id;
    document.writeln([
'<div id="fontSizeChange" class="cbox">',
'<img src="' + HOST_ROOT + 'images/fontsizeguide.gif" alt="フォントサイズ" class="fsizeguide" />',
'<img src="' + HOST_ROOT + 'images/fontsize_small.gif" id="fontSizeChangeSmall" class="rollover" alt="小" />',
'<img src="' + HOST_ROOT + 'images/fontsize_normal.gif" id="fontSizeChangeNormal" class="rollover" alt="中" />',
'<img src="' + HOST_ROOT + 'images/fontsize_large.gif" id="fontSizeChangeLarge" class="rollover" alt="大" />',
'</div>'
    ].join("\n"));
    Event.observe($('fontSizeChangeSmall' ), 'click', this.onClickSmall.bind(this));
    Event.observe($('fontSizeChangeNormal'), 'click', this.onClickNormal.bind(this));
    Event.observe($('fontSizeChangeLarge' ), 'click', this.onClickLarge.bind(this));
  },
  onClickSmall:  function(e) { this.change('83.3%' ); },
  onClickNormal: function(e) { this.change('100%'); },
  onClickLarge:  function(e) { this.change('116.6%'); }
};
// Bootstrap
FontChanger.start = function(id) {
  var fontChanger = new FontChanger(id);
  fontChanger.show();
};
