// FontChanger
// Copyright (c) 2007 Hirotaka Ogawa
// REQUIRES: prototype.js, cookiemanager.js
FontChanger = Class.create();
FontChanger.prototype = {
  id: null,
  cookieManager: null,
  cookieName: 'fontSize',
  initialize: function(id) {
    this.id = name || 'fontChanger';
    this.cookieManager = new CookieManager();
    var fontSize = this.cookieManager.getCookie(this.cookieName);
    if (fontSize == 'small'){
      this.toSmall();
    } else if (fontSize == 'large'){
      this.toLarge();
    }
  },
  setCookieShelfLife: function(days) {
    this.cookieManager.cookieShelfLife = days;
  },
  change: function(id, fontSize) {
    var element = document.getElementById(id);
    element.style.fontSize = fontSize;
  },
  toSmall: function() {
    this.change('main', '90%');
    this.change('relatedLink', '90%');
    this.change('sidemenu', '85%');
    this.cookieManager.setCookie(this.cookieName, 'small');
  },
  toLarge: function() {
    this.change('main', '120%');
    this.change('relatedLink', '110%');
    this.change('sidemenu', '100%');
    this.cookieManager.setCookie(this.cookieName, 'large');
  },
  reset: function() {
    this.change('main', '');
    this.change('relatedLink', '');
    this.change('sidemenu', '');
    this.cookieManager.clearCookie(this.cookieName);
  },
  show: function() {
    Event.observe($('fc-small' ), 'click', this.onClickSmall.bind(this));
    Event.observe($('fc-medium'), 'click', this.onClickMedium.bind(this));
    Event.observe($('fc-large' ), 'click', this.onClickLarge.bind(this));
  },
  onClickSmall:  function(e) { this.toSmall(); },
  onClickMedium: function(e) { this.reset(); },
  onClickLarge:  function(e) { this.toLarge(); }
};
// Bootstrap
FontChanger.start = function(name) {
  var fontChanger = new FontChanger(name);
  fontChanger.show();
};
