// 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);
	
	var id = this.id;
	//alert(fontSize);
	// 選択されている内容でメニューを切替
	if(fontSize=="10px"){
		document.body.style.lineHeight = "18px";
		document.getElementById(id + '-large').innerHTML = '<img src="common/img/button_big_off.gif" width="19" height="19" alt="">';
		document.getElementById(id + '-medium').innerHTML = '<img src="common/img/button_middle_off.gif" width="19" height="19" alt="">';
		document.getElementById(id + '-small').innerHTML = '<img src="common/img/button_small_on.gif" width="19" height="19" alt="">';
	}else if(fontSize=="12px"){
		document.body.style.lineHeight = "20px";
		document.getElementById(id + '-large').innerHTML = '<img src="common/img/button_big_off.gif" width="19" height="19" alt="">';
		document.getElementById(id + '-medium').innerHTML = '<img src="common/img/button_middle_on.gif" width="19" height="19" alt="">';
		document.getElementById(id + '-small').innerHTML = '<img src="common/img/button_small_off.gif" width="19" height="19" alt="">';
	}else if(fontSize=="14px"){
		document.body.style.lineHeight = "22px";
		document.getElementById(id + '-large').innerHTML = '<img src="common/img/button_big_on.gif" width="19" height="19" alt="">';
		document.getElementById(id + '-medium').innerHTML = '<img src="common/img/button_middle_off.gif" width="19" height="19" alt="">';
		document.getElementById(id + '-small').innerHTML = '<img src="common/img/button_small_off.gif" width="19" height="19" alt="">';
	}
  },
  reset: function() {
    document.body.style.fontSize = '';
    this.cookieManager.clearCookie(this.cookieName);
  },
  show: function() {
    var id = this.id;
	
    document.writeln(
		'<div id="' + id + '">',
		'<img src="common/img/img_textsize.gif" width="67" height="19" alt="">',
		'<span style="cursor: pointer; margin-left: 4px;" id="' + id + '-large" ><img src="common/img/button_small_off.gif" width="19" height="19" alt=""></span>',
		'<span style="cursor: pointer; margin-left: 4px;" id="' + id + '-medium"><img src="common/img/button_middle_off.gif" width="19" height="19" alt=""></span>',
		'<span style="cursor: pointer; margin-left: 4px;" id="' + id + '-small" ><img src="common/img/button_big_off.gif" width="19" height="19" alt=""></span>',
		'</div>');
	
	document.body.style.lineHeight = "20px";
	
	// 選択されている内容でメニューを切替
	if(this.cookieManager.getCookie(this.cookieName)=="10px"){
		document.body.style.lineHeight = "18px";
		document.getElementById(id + '-large').innerHTML = '<img src="common/img/button_big_off.gif" width="19" height="19" alt="">';
		document.getElementById(id + '-medium').innerHTML = '<img src="common/img/button_middle_off.gif" width="19" height="19" alt="">';
		document.getElementById(id + '-small').innerHTML = '<img src="common/img/button_small_on.gif" width="19" height="19" alt="">';
	}else if(this.cookieManager.getCookie(this.cookieName)=="14px"){
		document.body.style.lineHeight = "22px";
		document.getElementById(id + '-large').innerHTML = '<img src="common/img/button_big_on.gif" width="19" height="19" alt="">';
		document.getElementById(id + '-medium').innerHTML = '<img src="common/img/button_middle_off.gif" width="19" height="19" alt="">';
		document.getElementById(id + '-small').innerHTML = '<img src="common/img/button_small_off.gif" width="19" height="19" alt="">';
	}else{
		document.body.style.lineHeight = "20px";
		document.getElementById(id + '-large').innerHTML = '<img src="common/img/button_big_off.gif" width="19" height="19" alt="">';
		document.getElementById(id + '-medium').innerHTML = '<img src="common/img/button_middle_on.gif" width="19" height="19" alt="">';
		document.getElementById(id + '-small').innerHTML = '<img src="common/img/button_small_off.gif" width="19" height="19" alt="">';
	}
	
    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('10px' ); },
  onClickMedium: function(e) { this.change('12px'); },
  onClickLarge:  function(e) { this.change('14px'); }
};
// Bootstrap
FontChanger.start = function(id) {
  var fontChanger = new FontChanger(id);
  fontChanger.show();
};

