var fontSizeSwitcher = {
	config: {
		area:        ['.contentsLeft', '.topContentsCenter'], /* フォントサイズチェンジを適応するエリアID */
		id:          ['','fontSizeNormal', 'fontSizeLarge'],
		label:       ['','<a href="javascript:void(0)"><img src="/common/images/header_font-size_normal.gif" alt="標準" width="33" height="17" /></a>', '<a href="javascript:void(0)"><img src="/common/images/header_font-size_large.gif" alt="拡大" width="33" height="17" /></a>'],
		size:        ['','100%', '115%'],
		description: '<img src="/common/images/header_font-size.gif" alt="文字サイズ" width="45" height="9" />',
		cookieName:  'サイト名：fontSize',
		cookieDate:  90
	},

	changeFontSize: function(size) {
		var config = this.config;
		var items  = document.getElementById('fontSizeChange').childNodes;
		var ss     = document.styleSheets[0];

		for (var i = 0, l = items.length; i < l ; i++) {
			if (size == i) {
				this.setClassName(items[i], 'current');
			}
			else {
				this.removeClassName(items[i]);
			}
		}

		for (var i = 0, l = config.area.length; i < l; i++) {
			if (window.attachEvent && !window.opera) {
				ss.addRule(config.area[i], 'font-size: ' + config.size[size]  + ';');
			}
			else {
				ss.insertRule(config.area[i] + '{ font-size: ' + config.size[size]  + '; }', ss.cssRules.length);
			}
		}


		this.setCookie(size);
	},

	setCookie: function(data) {
		var t = new Date();
		t.setTime(t.getTime() + (1000 * 60 * 60 * 24 * Number(this.config.cookieDate)));
		document.cookie = this.config.cookieName + '=' + encodeURIComponent(data) + '; path=/; expires=' + t.toGMTString();
	},

	getCookie: function(m) {
		return (m = ('; ' + document.cookie + ';').match('; ' + this.config.cookieName + '=(.*?);')) ? decodeURIComponent(m[1]) : null;
	},

	setClassName: function(elem, str) {
		(window.attachEvent && !window.opera) ? elem.className = str : elem.setAttribute('class', str);
	},

	removeClassName: function(elem) {
		(window.attachEvent && !window.opera) ? elem.removeAttribute('className') : elem.removeAttribute('class');
	},

	start: function() {
		var config = this.config;
		var size   = this.getCookie('s');
		var str    = '';

		for (var i = 1, l = config.id.length; i < l ; i++) {
			str += '<dd id="' + config.id[i] + '" onclick="fontSizeSwitcher.changeFontSize(' + i + ')">' + config.label[i] + '</dd>';
		}

		document.write('<dl id="fontSizeChange"><dt>' + config.description + '</dt>' + str + '</dl>');

		if (size == null) {
			size = 1;
		}

		this.changeFontSize(size);
	}
}

fontSizeSwitcher.start();