/* ------------------------------------------------------------------------
フォントサイズ変更 (with CookieManager)
	Copyright (c) 2009, Matsumoto.JS All rights reserved.

【使用方法】（なるべく<head>タグ内にて）
<script src="js/prototype.js" type="text/javascript"></script>
<script src="js/cookie.js" type="text/javascript"></script>
<script src="js/fontsize.js" type="text/javascript"></script>
<script>
document.observe('dom:loaded', function(){new FontResize();});
</script>

HTMLでは、
<ul class="panel">
	<li id="font-small">小</li>
	<li id="font-normal">標準</li>
	<li id="font-large">大</li>
</ul>
などと指定します。各サイズにそれぞれ、
通常時：normal、選択時：select が動的にクラス指定されますので
CSSで表示を準備・調整します

【パラメータの説明】
option: オブジェクトリテラルで指定
	target: サイズ変更を有効にする範囲（default:"content"）
	expire: 有効期間（default:0=セッション限り）
table: 文字サイズ変更のサイズテーブル
	サイズを変えたい、「小」を無くすなどのカスタマイズをする場合
	var newtable = {
		'normal': {'id': 'font-normal', 'size': '100%'},
		'large':  {'id': 'font-large',  'size': '150%'}
	};
	new FontResize({target:'content'}, newtable);
 ------------------------------------------------------------------------ */
FontResize = Class.create();
FontResize.prototype = {

fsize: {
	'small':  {'id': 'font-small',  'size':  '85%'},
	'normal': {'id': 'font-normal', 'size': '100%'},
	'large':  {'id': 'font-large',  'size': '120%'}
},

initialize: function(option, table) {
	this.props = { target: 'content', expire: 0 };
	if(option) for(var key in option) this.props[key] = option[key];
	this.cookiemgr = new CookieManager({expire: this.props.expire});
	this.currentFontSize = 'normal';
	
	if (table) this.fsize = table;
	for (key in this.fsize)
		$(this.fsize[key]['id']).observe(
			'click', function(k){this.resizeFont(k);}.bind(this,key)
		).addClassName('normal').style['cursor'] = 'pointer';
	var cookieValue = this.cookiemgr.getCookie("currentFontSize");
	if (cookieValue) this.currentFontSize = cookieValue;
	this.resizeFont(this.currentFontSize);
},

resizeFont: function(size) {
	for (key in this.fsize)
		$(this.fsize[key]['id']).removeClassName('select');
	var obj = this.fsize[size];
	$(this.props.target).style.fontSize = obj['size'];
	$(obj['id']).addClassName('select');
	this.cookiemgr.setCookie("currentFontSize", size);
}
}//prototype
