// FontChanger
// Copyright (c) 2007 Hirotaka Ogawa
// REQUIRES: prototype.js, cookiemanager.js
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 = '100%';
    if(this.cookieManager.getCookie(this.cookieName) == '120%'){
      fontSize = '120%';
    }
    //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="' + id + '">',
'<dl><dt title="文字サイズ">文字サイズの変更</dt> ',
'<dd id="tsize_nomal"><a href="javascript:void(0);">文字を標準にする</a></dd>',
'<dd id="tsize_up"><a href="javascript:void(0);">文字を拡大する</a></dd>',
'</dl></div>'
    ].join("\n"));
    Event.observe($('tsize_nomal'), 'click', this.onClickMedium.bind(this));
    Event.observe($('tsize_up' ), '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(90);
  fontChanger.show();
};

