// 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([
'<div id="' + id + '">',
'<img src="/img_common/ob_fontchange.gif" alt="文字サイズ変更" width="130" height="25" border="0" usemap="#Map" />',
'<map name="Map">',
'<area shape="rect" coords="103,4,126,22" id="' + id + '-large" alt="大" href="#">',
'<area shape="rect" coords="81,4,102,22" id="' + id + '-medium" alt="中" href="#">',
'<area shape="rect" coords="63,4,80,22" id="' + id + '-small" alt="小" href="#">',
'</map>',
'</div>'
    ].join(""));
    Event.observe($(id + '-small' ), 'click', this.onClickSmall.bind(this));
    Event.observe($(id + '-medium'), 'click', this.onClickMedium.bind(this));
    Event.observe($(id + '-large' ), 'click', this.onClickLarge.bind(this));
  },
  onClickSmall:  function(e) { this.change('12px'); },
  onClickMedium: function(e) { this.change('14px'); },
  onClickLarge:  function(e) { this.change('16px'); }
};
// Bootstrap
FontChanger.start = function(id) {
  var fontChanger = new FontChanger(id);
  fontChanger.show();
};
