var switchFontSize = {
	
	conf : {
		fontSize    : ["123%","100%","82%"],
		switchId    : ["switchFontSizeBig", "switchFontSizeMedium", "switchFontSizeSmall"],
		defoSizeId  : "switchFontSizeMedium",
		targetAreaId: "contentBaseWrap",              //フォントサイズを適用するエリアのID
		cookieName  : "FontSize",      //クッキーの名前
		cookieLimit : 30,                     //有効期限(日にち)
		switchWriteArea : "fontResizeBlock",          //指定したIDのエリアの一番最後にスイッチのHTMLが書き込まれる
		switchHTML      : '<dl><dt>文字サイズ</dt><dd id="switchFontSizeSmall">小</dd><dd id="switchFontSizeMedium">中</dd><dd id="switchFontSizeBig">大</dd></dl>'
	},
	
	main : function(){
		switchFontSize.setHTML();
		switchFontSize.defo();
		var i, j, switchItem = switchFontSize.conf.switchId;
		
		for(i=0;i<switchItem.length;i++){
			document.getElementById(switchItem[i]).onclick = switchFontSize.action;
		}
	},
	
	setHTML : function(){
		var fontsizeSwitch = document.createElement('div'); 
		fontsizeSwitch.id  = "fontsizeControl";
		fontsizeSwitch.innerHTML = switchFontSize.conf.switchHTML; 
		
		document.getElementById(switchFontSize.conf.switchWriteArea).appendChild(fontsizeSwitch);
	},
	
	defo : function(){
		var i;
		var switchId = switchFontSize.conf.switchId;
		var targetAreaId = switchFontSize.conf.targetAreaId;
		var fontSize = switchFontSize.conf.fontSize;
		
		cookieValue = this.getCookie() || switchFontSize.conf.defoSizeId;
		for(i = 0; i < switchId.length; i++){
			if(cookieValue == switchId[i]){
				document.getElementById(targetAreaId).style.fontSize = fontSize[i];
			}
		}
		document.getElementById(cookieValue).className ="active";
	},
	
	action : function(){
		var i;
		var switchId = switchFontSize.conf.switchId;
		var targetAreaId = switchFontSize.conf.targetAreaId
		var fontSize = switchFontSize.conf.fontSize
		
		for(i=0;i<switchId.length;i++){
			var switchItem = document.getElementById(switchId[i]);
			switchItem.className="";
			if(this.id == switchId[i]){
				document.getElementById(targetAreaId).style.fontSize = fontSize[i];
			}
		}
		this.className ="active";
		
		switchFontSize.setCookie(this.id);
	},
	
	setCookie: function(data) {
		var today = new Date();
		today.setTime(today.getTime() + (1000 * 60 * 60 * 24 * Number(this.conf.cookieLimit)));
		document.cookie = this.conf.cookieName + '=' + encodeURIComponent(data) + '; path=/; expires=' + today.toGMTString();
	},
	
	getCookie: function(m) {
		return (m = ('; ' + document.cookie + ';').match('; ' + this.conf.cookieName + '=(.*?);')) ? decodeURIComponent(m[1]) : null;
	},
	
	addEvent : function(){
		if(window.addEventListener) {
			window.addEventListener("load", this.main, false);
		}
		else if(window.attachEvent) {
			window.attachEvent("onload", this.main);
		}
	}
	
}

switchFontSize.addEvent();

