// FontChanger
// Copyright (c) 2007 Hirotaka Ogawa
// REQUIRES: prototype.js, cookiemanager.js
FontChanger = Class.create();
FontChanger.prototype = {
	id: null,
	cookieManager: null,
	cookieName: 'body.style.fontSize',

// ファイルパス指定===============================================================================================
  filepath: pageDegree,
//=================================================================================================================

	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;
		//if (fontSize) document.getElementById('font').href= this.filepath + '/common/css/' + fontSize + '.css';
		document.getElementById('page').style.fontSize = fontSize;

	},
	setCookieShelfLife: function(days) {
		this.cookieManager.cookieShelfLife = days;
	},
	change: function(fontSize) {
		//document.body.style.fontSize = fontSize;
		//document.getElementById('font').href = this.filepath + '/common/css/' + fontSize + '.css';
		document.getElementById('page').style.fontSize = fontSize;

		this.cookieManager.setCookie(this.cookieName, fontSize);

		var id = this.id;
		//alert(fontSize);
		// 選択されている内容でメニューを切替
		if(fontSize=="85%"){
			document.getElementById(id + '-small').innerHTML = '<img src="' + this.filepath + '/common/images/size-s-on.gif" width="15" height="19" id="" alt="小" />';
			document.getElementById(id + '-medium').innerHTML = '<img src="' + this.filepath + '/common/images/size-m.gif" width="17" height="19" alt="中" />';
			document.getElementById(id + '-large').innerHTML = '<img src="' + this.filepath + '/common/images/size-l.gif" id="img-l" width="19" height="19" alt="大" />';
		}else if(fontSize=="100%"){
			document.getElementById(id + '-small').innerHTML = '<img src="' + this.filepath + '/common/images/size-s.gif" width="15" height="19" id="" alt="小" />';
			document.getElementById(id + '-medium').innerHTML = '<img src="' + this.filepath + '/common/images/size-m-on.gif" width="17" height="19" alt="中" />';
			document.getElementById(id + '-large').innerHTML = '<img src="' + this.filepath + '/common/images/size-l.gif" id="img-l" width="19" height="19" alt="大" />';
		}else if(fontSize=="123%"){
			document.getElementById(id + '-small').innerHTML = '<img src="' + this.filepath + '/common/images/size-s.gif" width="15" height="19" id="" alt="小" />';
			document.getElementById(id + '-medium').innerHTML = '<img src="' + this.filepath + '/common/images/size-m.gif" width="17" height="19" alt="中" />';
			document.getElementById(id + '-large').innerHTML = '<img src="' + this.filepath + '/common/images/size-l-on.gif" id="img-l" width="19" height="19" alt="大" />';
		}
	},
	reset: function() {
		document.body.style.fontSize = '';
		this.cookieManager.clearCookie(this.cookieName);
	},
	show: function() {
		var id = this.id;
	
		document.writeln(
			'<p id="' + id + '" class="size"><img src="' + this.filepath + '/common/images/size-text.gif" width="54" height="19" alt="文字サイズ" /><span style="cursor: pointer;" id="' + id + '-small" ><img src="' + this.filepath + '/common/images/size-s.gif" width="15" height="19" id="" alt="小" /></span><span style="cursor: pointer;" id="' + id + '-medium"><img src="' + this.filepath + '/common/images/size-m-on.gif" width="17" height="19" alt="中" /></span><span style="cursor: pointer;" id="' + id + '-large" ><img src="' + this.filepath + '/common/images/size-l.gif" id="img-l" width="19" height="19" alt="大" /></span></p>'
		);
	
		// 選択されている内容でメニューを切替
		if(this.cookieManager.getCookie(this.cookieName)=="85%"){
			document.getElementById(id + '-small').innerHTML = '<img src="' + this.filepath + '/common/images/size-s-on.gif" width="15" height="19" id="" alt="小" />';
			document.getElementById(id + '-medium').innerHTML = '<img src="' + this.filepath + '/common/images/size-m.gif" width="17" height="19" alt="中" />';
			document.getElementById(id + '-large').innerHTML = '<img src="' + this.filepath + '/common/images/size-l.gif" id="img-l" width="19" height="19" alt="大" />';
		}else if(this.cookieManager.getCookie(this.cookieName)=="100%"){
			document.getElementById(id + '-small').innerHTML = '<img src="' + this.filepath + '/common/images/size-s.gif" width="15" height="19" id="" alt="小" />';
			document.getElementById(id + '-medium').innerHTML = '<img src="' + this.filepath + '/common/images/size-m-on.gif" width="17" height="19" alt="中" />';
			document.getElementById(id + '-large').innerHTML = '<img src="' + this.filepath + '/common/images/size-l.gif" id="img-l" width="19" height="19" alt="大" />';	}else if(this.cookieManager.getCookie(this.cookieName)=="123%"){
			document.getElementById(id + '-small').innerHTML = '<img src="' + this.filepath + '/common/images/size-s.gif" width="15" height="19" id="" alt="小" />';
			document.getElementById(id + '-medium').innerHTML = '<img src="' + this.filepath + '/common/images/size-m.gif" width="17" height="19" alt="中" />';
			document.getElementById(id + '-large').innerHTML = '<img src="' + this.filepath + '/common/images/size-l-on.gif" id="img-l" 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('85%' ); },
	onClickMedium: function(e) { this.change('100%'); },
	onClickLarge:  function(e) { this.change('123%'); }
};
// Bootstrap
FontChanger.start = function(id) {
	var fontChanger = new FontChanger(id);
	fontChanger.show();
};
