// 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 = 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([
'<a href="javascript:void(0)" id="font_small" onclick="fs_small();">小</a><a href="javascript:void(0)" id="font_medium" onclick="fs_medium();">中</a><a href="javascript:void(0)" id="font_large" onclick="fs_large();">大</a>'
    ].join("\n"));
    Event.observe($('font_small'), 'click', this.onClickSmall.bind(this));
    Event.observe($('font_medium'), 'click', this.onClickMedium.bind(this));
    Event.observe($('font_large'), 'click', this.onClickLarge.bind(this));
  },
  onClickSmall:  function(e) { this.change('78%' ); },
  onClickMedium: function(e) { this.change('80%'); },
  onClickLarge:  function(e) { this.change('90%'); }
};
// Bootstrap
FontChanger.start = function(id) {
  var fontChanger = new FontChanger(id);
  fontChanger.show();
};
