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 = 30;
  },
  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 + '">',
'<div style="float:left;width:70px;"><img src="images/f-size-img01.gif" alt="文字の大きさ" width="67" height="16" /></div>','<span style="cursor: pointer;" id="' + id + '-small" ><img src="images/f-size-img-s.gif" alt="小" width="39" height="16" border="0" /></span>','<span style="cursor: pointer;" id="' + id + '-medium"><img src="images/f-size-img-m.gif" alt="中" width="38" height="16" border="0" /></span>','<span style="cursor: pointer;" id="' + id + '-large" ><img src="images/f-size-img-l.gif" alt="大" width="39" height="16" border="0" /></span>','</div>'
    ].join("\n"));
    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('85%' ); },
  onClickMedium: function(e) { this.change('100%'); },
  onClickLarge:  function(e) { this.change('115%'); }
};
// Bootstrap
FontChanger.start = function(id) {
  var fontChanger = new FontChanger(id);
  fontChanger.show();
};

