var fontSizeSwitcher = {
	str: '',
	config: {
		area: ['contents'], // 対象ID
		length: 3, // スイッチの数
		id: ['fssSmall', 'fssMedium', 'fssLarge'], // スイッチの各ID
		label: ['Small', 'Medium', 'Large'], // スイッチのラベル
		size: ['85%', '100%', '114%'], // 変更時のフォントサイズ
		cookieName: 'NP-T_FSS', // クッキー名
		cookieDate: '90' // このクッキーの有効日数
	},

	cookie: {
		set: function(n, v) {
			var t = new Date();
			t.setTime(t.getTime() + (1000 * 60 * 60 * 24 * fontSizeSwitcher.config.cookieDate));
			document.cookie = n + '=' + encodeURIComponent(v) + '; path=/; expires=' + t.toGMTString();
		},
		get: function(n, m) {
			return (m = ('; ' + document.cookie + ';').match('; ' + n + '=(.*?);')) ? decodeURIComponent(m[1]) : '';
		}
	},

	changeFontSize: function(i) {
		var config = this.config;

		var items = document.getElementById('fontSizeSwitcher').childNodes;
		for(var j = 0; j < items.length; j++) {
			if(i == j) {
				items[j].setAttribute('class', 'current');
			}
			else {
				items[j].removeAttribute('class');
			}
		}

		for(var j = 0, l = config.area.length; j < l; j++) {
			document.getElementById(config.area[j]).style.fontSize = config.size[i];
		}

		// set cookie
		this.cookie.set(config.cookieName, i);
	},

	start: function() {
		var config = this.config;
		var i      = this.cookie.get(config.cookieName, 's');

		for(var j = 0; j < config.length; j++) {
			this.str += '<li id="' + config.id[j] + '" onclick="fontSizeSwitcher.changeFontSize(' + j + ')">' + config.label[j] + '</li>';
		}

		document.write('<ul id="fontSizeSwitcher">' + this.str + '</ul>');

		if(i == '') {
			i = 1;
		}

		try {
			window.addEventListener("load", function() {
				fontSizeSwitcher.changeFontSize(i)
			}, false);
		}
		catch(e) {
			window.attachEvent("onload", function() {
				fontSizeSwitcher.changeFontSize(i)
			});
		}
	}
}

fontSizeSwitcher.start();