// FontChanger
// 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;
		document.writeln([
'<div id="' + id + '">',
'<img src="http://www.fukuic-shakyo.jp/imgs/fontsize_title.png" alt="文字サイズ" /><br />',
'<span style="cursor: pointer; font-size: 90% ;" id="' + id + '-small" ><img src="http://www.fukuic-shakyo.jp/imgs/fontsize_small.png" alt="小" /></span>',
'<span style="cursor: pointer; font-size: 100%;" id="' + id + '-medium"><img src="http://www.fukuic-shakyo.jp/imgs/fontsize_medium.png" alt="中" /></span>',
'<span style="cursor: pointer; font-size: 120%;" id="' + id + '-large" ><img src="http://www.fukuic-shakyo.jp/imgs/fontsize_large.png" alt="大" /></span>',
'</div>'
		].join(""));
		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('90%'); },
	onClickMedium: function(e) { this.change('100%'); },
	onClickLarge: function(e) { this.change('120%'); }
};
FontChanger.start = function(id) {
	var fontChanger = new FontChanger(id);
	fontChanger.setCookieShelfLife(90);
	fontChanger.show();
};