var fontSizeSwitcher = {
	config: [
		{
			id: 'fontSizeSwitcherSmall',
			label: '小',
			size: '77%'
		},
		{
			id: 'fontSizeSwitcherMedium',
			label: '中',
			size: '100%'
		},
		{
			id: 'fontSizeSwitcherLarge',
			label: '大',
			size: '122%'
		}
	],
	cookieName: 'fontSizeSwitcher',
	cookieDate: '90',

	setCookie: function(n, v) {
		var t = new Date();
		t.setTime(t.getTime() + (1000 * 60 * 60 * 24 * fontSizeSwitcher.cookieDate));
		document.cookie = n + '=' + encodeURIComponent(v) + '; path=/; expires=' + t.toGMTString();
	},

	getCookie: function(n, m) {
		return (m = ('; ' + document.cookie + ';').match('; ' + n + '=(.*?);')) ? decodeURIComponent(m[1]) : '';
	},

	changeFontSize: function(index) {
		$('#fontSizeSwitcher > li').each(function(i) {
			if (index == i)
				$(this).attr('class', 'current');
			else
				$(this).removeAttr('class');
		});
		$('#content').css({fontSize: this.config[index].size});

		this.setCookie(this.cookieName, index);
	},

	run: function() {
		var self = this;
		var index = this.getCookie(this.cookieName, 's')

		var str = '';
		$.each(this.config, function(i) {
			str += [
				'<li id="' + this.id + '">',
				'<a href="javascript:void(0)" onclick="fontSizeSwitcher.changeFontSize(' + i + ')">' + this.label + '</a>',
				'</li>'
			].join('');
		});

		document.write([
			'<dl id="fontSizeController">',
			'<dt><img src="/shared/img/title/text_size.gif" alt="文字サイズ" /></dt>',
			'<dd><ul id="fontSizeSwitcher">' + str + '</ul></dd></dl>'
		].join(''));

		$(document).ready(function() {
			if (index)
				fontSizeSwitcher.changeFontSize(index);
			else
				fontSizeSwitcher.changeFontSize(1);
		});
	}
}

fontSizeSwitcher.run();
