// 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;
    var size = this.cookieManager.getCookie(this.cookieName);
	if(this.cookieManager.getCookie(this.cookieName) == '100%'){
		document.writeln([
		'<div id="' + id + '">',
		'<img src="/img_icon/h_text_size_ttl.gif" border="0" alt="文字サイズ" />',
		//'<span style="cursor: pointer; ;" id="' + id + '-small" >小</span>',		//小
		'<span style="cursor: pointer;" id="' + id + '-medium"><img src="/img_icon/h_text_size_M_off.gif" border="0" alt="" /></span>',	//中
		'<span id="' + id + '-large" ></span><img src="/img_icon/h_text_size_L_on.gif" border="0" alt="" />',		//大
		'<!--現在サイズ：' + size + ' --> ',
		'</div>'
	].join("\n"));
	}else{
		document.writeln([
		'<div id="' + id + '">',
		'<img src="/img_icon/h_text_size_ttl.gif" border="0" alt="文字サイズ" />',
		//'<span style="cursor: pointer; ;" id="' + id + '-small" >小</span>',		//小
		'<span id="' + id + '-medium"></span><img src="/img_icon/h_text_size_M_on.gif" border="0" alt="" />',	//中
		'<span style="cursor: pointer;" id="' + id + '-large" ><img src="/img_icon/h_text_size_L_off.gif" border="0" alt="" /></span>',		//大
		'<!--現在サイズ：' + size + ' --> ',
		'</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) {location.reload(); this.change('80%' ); },	//小
  onClickMedium: function(e) {location.reload(); this.change('80%'); },	//中
  onClickLarge:  function(e) {location.reload(); this.change('100%'); }		//大
};
// Bootstrap
FontChanger.start = function(id) {
  var fontChanger = new FontChanger(id);
  fontChanger.show();
};