// FontChanger
// Copyright (c) 2007 Hirotaka Ogawa
// REQUIRES: prototype.js, cookiemanager.js

FontChanger = Class.create();
FontChanger.prototype = {
  id: null,
  cookieManager: null,
  cookieName: 'getElementById("container").style.fontSize',
  initialize: function(id) {
    this.id = id || 'fontChanger';
    this.cookieManager = new CookieManager();
    var fontSize = this.cookieManager.getCookie(this.cookieName);
    if (fontSize) window.onload = function() { document.getElementById("container").style.fontSize = fontSize; }
  },
  setCookieShelfLife: function(days) {
    this.cookieManager.cookieShelfLife = days;
  },
  change: function(fontSize) {
    document.getElementById("container").style.fontSize = fontSize;
    this.cookieManager.setCookie(this.cookieName, fontSize);
  },
  reset: function() {
    document.getElementById("container").style.fontSize = '';
    this.cookieManager.clearCookie(this.cookieName);
  },
  show: function() {
    var id = this.id;
    document.writeln([
'<div id="cont">',
'글자 크기',
'<a href="javascript:void(0);" id="'+id+'-small"><img src="http://ryumeikan-tokyo.jp/common/img/flonavi/size01.png" width="17" height="19" alt="A" /></a>',
'<a href="javascript:void(0);" id="'+id+'-medium"><img src="http://ryumeikan-tokyo.jp/common/img/flonavi/size02.png" width="17" height="19" alt="A" /></a>',
'<a href="javascript:void(0);" id="'+id+'-large"><img src="http://ryumeikan-tokyo.jp/common/img/flonavi/size03.png" width="17" height="19" alt="A" /></a>',
'</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('80%' ); },
  onClickMedium: function(e) { this.change('100%'); },
  onClickLarge:  function(e) { this.change('140%'); }
};
// Bootstrap
FontChanger.start = function(id) {
  var fontChanger = new FontChanger(id);
  fontChanger.show();
};
