// FontChanger
// Copyright (c) 2007 Hirotaka Ogawa
// REQUIRES: prototype.js, cookiemanager.js

//変更領域のID名
 BodyID = "main";
//設定サイズ
 DefS = "75%";
 DefM = "85%";
 DefL = "110%";
//設定ここまで


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.getElementById(BodyID).style.fontSize = fontSize; 
  },
  setCookieShelfLife: function(days) {
    this.cookieManager.cookieShelfLife = days;
  },
  change: function(fontSize) {
    document.getElementById(BodyID).style.fontSize = fontSize;
    this.cookieManager.setCookie(this.cookieName, fontSize);
  },
  reset: function() {
    document.getElementById(BodyID).style.fontSize = '';
    this.cookieManager.clearCookie(this.cookieName);
  },
  show: function() {
    var id = this.id;
    document.writeln([
'<div id="' + id + '">',
'<span id="' + id + '-name" >文字の大きさ:</span> ',
'<span style="cursor: pointer; font-size: ' + DefS + ' ;" id="' + id + '-small" >小</span>',
'<span style="cursor: pointer; font-size: ' + DefM + ';" id="' + id + '-medium">中</span>',
'<span style="cursor: pointer; font-size: ' + DefL + ';" id="' + id + '-large" >大</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(DefS); },
  onClickMedium: function(e) { this.change(DefM); },
  onClickLarge:  function(e) { this.change(DefL); }
};
// Bootstrap
FontChanger.start = function(id) {
  var fontChanger = new FontChanger(id);
  fontChanger.show();
};