// FontChanger
// Copyright (c) 2007 Hirotaka Ogawa
// REQUIRES: prototype.js, cookiemanager.js
// Class変更対応版　2008 三菱商事太陽
// トップページ用　全体を表示変更する

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) {
		if(fontSize=='80%')setsmall();
		if(fontSize=='90%')setmedium();
		if(fontSize=='100%')setlarge();
		document.body.style.fontSize = fontSize;
		}
  },
  setCookieShelfLife: function(days) {
    this.cookieManager.cookieShelfLife = days;
  },
  change: function(fontSize) {
    document.body.style.fontSize = fontSize;
		if(fontSize=='80%')setsmall();
		if(fontSize=='90%')setmedium();
		if(fontSize=='100%')setlarge();
    this.cookieManager.setCookie(this.cookieName, fontSize);
  },
  reset: function() {
    document.body.style.fontSize = '';
    this.cookieManager.clearCookie(this.cookieName);
	setmedium();
  },
  show: function() {
    var id = this.id;
    document.writeln([
'<div id="' + id + '">',
'<div id="moji">文字の大きさ</div>',
'<div style="cursor: pointer; font-size: 80%;" id="' + id + '-small"><span id="small">小</span></div>',
'<div style="cursor: pointer; font-size: 90%;" id="' + id + '-medium"><span id="medium">中</span></div>',
'<div style="cursor: pointer; font-size: 100%;" id="' + id + '-large" ><span id="large">大</span></div>',
'</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));
	    var fontSize = this.cookieManager.getCookie(this.cookieName);
    if (fontSize) {
		if(fontSize=='80%')setsmall();
		if(fontSize=='90%')setmedium();
		if(fontSize=='100%')setlarge();
		document.body.style.fontSize = fontSize;
		}
  },
  onClickSmall:  function(e) { this.change('80%' ); },
  onClickMedium: function(e) { this.change('90%'); },
  onClickLarge:  function(e) { this.change('100%'); }
};
// Bootstrap
FontChanger.start = function(id) {
  var fontChanger = new FontChanger(id);
  fontChanger.setCookieShelfLife(90);
  fontChanger.show();
};
