// 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([
'<ul id="' + id + '">',
'<li><span style="cursor: pointer; font-size: 10px;" id="' + id + '-small" ><img src="http://www.boatrace-miyajima.com/img/small.gif" width="17" height="17" alt="小" /></span></li>',
'<li><span style="cursor: pointer; font-size: 12px;" id="' + id + '-medium"><img src="http://www.boatrace-miyajima.com/img/midiam.gif" width="20" height="20" alt="中" /></span></li>',
'<li><span style="cursor: pointer; font-size: 14px;" id="' + id + '-large" ><img src="http://www.boatrace-miyajima.com/img/large.gif" width="22" height="22" alt="大" /></span></li>',
'</ul>'
    ].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('55%' ); },
  onClickMedium: function(e) { this.change('62.5%'); },
  onClickLarge:  function(e) { this.change('72%'); }
};
// Bootstrap
FontChanger.start = function(id) {
  var fontChanger = new FontChanger(id);
  fontChanger.show();
};
