// JavaScript Document

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([
    '<ul id="' + id + '">',
      '<li class="caption"><span>文字の大きさ</span></li>',
      '<li class="normal"><a href="javascript: void(0);" title="標準サイズ" id="' + id + '-medium" onclick="bgchange(this.id)"><span>標準</span></a></li>',
      '<li class="zoom"><a href="javascript: void(0);" title="大きめのサイズ" id="' + id + '-large" onclick="bgchange(this.id)"><span>拡大</span></a></li>',
      '<br class="clearleft" />',
    '</ul>'
    ].join("\n"));
    Event.observe($(id + '-medium'), 'click', this.onClickMedium.bind(this));
    Event.observe($(id + '-large' ), 'click', this.onClickLarge.bind(this));
  },
  onClickMedium: function(e) { this.change('100%'); },
  onClickLarge:  function(e) { this.change('120%'); }
};
// Bootstrap
FontChanger.start = function(id) {
  var fontChanger = new FontChanger(id);
  fontChanger.setCookieShelfLife(1);
  fontChanger.show();
};

