// 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 + '">',
'文字サイズ: ',
'<a href="javascript:void(0);" style="cursor: pointer;" id="' + id + '-xsmall" title="文字サイズ：最小">-2</a>',
'<a href="javascript:void(0);" style="cursor: pointer;" id="' + id + '-small" title="文字サイズ：小">-1</a>',
'<a href="javascript:void(0);" style="cursor: pointer;" id="' + id + '-medium" title="文字サイズ：標準">&nbsp;0&nbsp;</a>',
'<a href="javascript:void(0);" style="cursor: pointer;" id="' + id + '-large" title="文字サイズ：大">+1</a>',
'<a href="javascript:void(0);" style="cursor: pointer;" id="' + id + '-xlarge" title="文字サイズ：最大">+2</a>',
'</div>'
    ].join("\n"));
    Event.observe($(id + '-xsmall' ), 'click', this.onClickxSmall.bind(this));
    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));
    Event.observe($(id + '-xlarge' ), 'click', this.onClickxLarge.bind(this));
  },
  onClickxSmall:  function(e) { this.change('75%' ); },
  onClickSmall:  function(e) { this.change('87.5%' ); },
  onClickMedium: function(e) { this.change('100%'); },
  onClickLarge:  function(e) { this.change('112.5%'); },
  onClickxLarge:  function(e) { this.change('125%'); }
};
// Bootstrap
FontChanger.start = function(id) {
	if (navigator.userAgent.indexOf('MSIE 5')!=-1 || navigator.userAgent.indexOf('MSIE 4')!=-1) { return; }
  var fontChanger = new FontChanger(id);
  fontChanger.show();
};
