// FontChanger
// Copyright (c) 2007 Hirotaka Ogawa
// REQUIRES: prototype.js, cookiemanager.js
//
// Custamize: 2007/10/03- Lines Inc.

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) Element.addClassName(document.body, fontSize);
  },
  setCookieShelfLife: function(days) {
    this.cookieManager.cookieShelfLife = days;
  },
  change: function(fontSize) {
    var id = this.id;
    this.cookieManager.setCookie(this.cookieName, fontSize);
	var allfontSize = new Array(); // <--
	allfontSize[0] = 'small';
	allfontSize[1] = 'medium';
	allfontSize[2] = 'large';
	for(var i=0; i<allfontSize.length; i++){
      if(Element.hasClassName(document.body, allfontSize[i])) Element.removeClassName(document.body, allfontSize[i]);
	} // <--
	Element.addClassName(document.body, fontSize);
  },
  reset: function() {
	var allfontSize = new Array(); // <--
	allfontSize[0] = 'small';
	allfontSize[1] = 'medium';
	allfontSize[2] = 'large';
	for(var i=0; i<allfontSize.length; i++){
      if(Element.hasClassName(document.body, allfontSize[i])) Element.removeClassName(document.body, allfontSize[i]);
	} // <--
    this.cookieManager.clearCookie(this.cookieName);
  },
  show: function() {
    var id = this.id;
    document.writeln([
'<div id="' + id + '">',
'<span class="text"><img src="/common/image/font-changer-text.gif" alt="テキストサイズの変更" width="100" height="10" /></span>',
'<span id="' + id + '-small" ><img src="/common/image/font-changer-s-off.gif" alt="小さいサイズ" width="14" height="25" /></span>',
'<span id="' + id + '-medium"><img src="/common/image/font-changer-m-off.gif" alt="普通のサイズ" width="15" height="35" /></span>',
'<span id="' + id + '-large" ><img src="/common/image/font-changer-l-off.gif" alt="大きいサイズ" width="16" height="45" /></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('small');  },
  onClickMedium: function(e) { this.change('medium'); },
  onClickLarge:  function(e) { this.change('large'); }
};
// Bootstrap
FontChanger.start = function(id) {
  var fontChanger = new FontChanger(id);
  fontChanger.show();
};