// 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();
    this.cookieManager.cookieShelfLife = 90;
    var fontSize = this.cookieManager.getCookie(this.cookieName);
	var size;

    if (fontSize){
		document.body.style.fontSize = fontSize;
	}
	
  },
  setCookieShelfLife: function(days) {
    this.cookieManager.cookieShelfLife = days;
},
  change: function(fontSize) {
    document.body.style.fontSize = fontSize;

	switch (fontSize) {
		case "110%" : size = "l";break;
		case "80%": size ="s";break;
		default:size = "m";
		}
	var urlname = "url(../image/moji_" + size + ".gif)";
	document.getElementById("font-change").style.backgroundImage = urlname;
	
    this.cookieManager.setCookie(this.cookieName, fontSize);
  },
  reset: function() {
    document.body.style.fontSize = '';

	document.getElementById("font-change").style.backgroundImage ="url(../image/moji_m.gif)";
	this.cookieManager.clearCookie(this.cookieName);
  },
  show: function() {
    var id = this.id;
    document.writeln([
	'<div id="' + id + '">',
	'<div id="font-change-moji">&nbsp;</div>',
	'<a href="javascript: void(0);" id="' + id + '-small" title="文字を小さくする">[小]</a>',
	'<a href="javascript: void(0);" id="' + id + '-medium" title="文字を標準に戻す">[中]</a>',
	'<a href="javascript: void(0);" id="' + id + '-large" title="文字を大きくする">[大]</a></div><br class="clearfloat" />',
    ].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('96%'); },*/
  onClickMedium: function(e) { this.reset(); },
  onClickLarge:  function(e) { this.change('110%');}
};
// Bootstrap
FontChanger.start = function(id) {
  var fontChanger = new FontChanger(id);
  fontChanger.show();
};