

yomotsuFontSizeSwitchConf = {
	fontSize    : ["167%","134%","100%"],
	targetAreaId: "document",            //フォントサイズを適用するエリアのID
	cookieName  : "subaruFontSize",      //クッキーの名前
	cookieLimit : 30,                    //有効期限(日にち)
	switchWriteArea : "header-inner",
	switchHTML      : '<p>change text size</p><ul><li id="fontSizeSwitchSmall" onClick="fontSizeSwitch(\'small\')">small size text</li><li id="fontSizeSwitchMedium" onClick="fontSizeSwitch(\'medium\')">medium size text</li><li id="fontSizeSwitchBig" onClick="fontSizeSwitch(\'big\')">large size text</li></ul>'


}



/*====================================================================================================

 main

====================================================================================================*/


function fontSizeSwitch(size){


if(size=="big"){
cookiePut(size);
size = yomotsuFontSizeSwitchConf.fontSize[0];
removeActive()
document.getElementById("fontSizeSwitchBig").className    ="active";
}
else if(size=="medium"){
cookiePut(size);
size = yomotsuFontSizeSwitchConf.fontSize[1];
removeActive()
document.getElementById("fontSizeSwitchMedium").className ="active";
}
else if(size=="small"){
cookiePut(size);
size = yomotsuFontSizeSwitchConf.fontSize[2];
removeActive()
document.getElementById("fontSizeSwitchSmall").className  ="active";
}

targetAreaId = yomotsuFontSizeSwitchConf.targetAreaId;
document.getElementById(targetAreaId).style.fontSize=size;
}

/* class active削除用
-----------------------------*/

function removeActive(){
	switchId = new Array("fontSizeSwitchBig", "fontSizeSwitchMedium", "fontSizeSwitchSmall");
	
	for(i=0;i<switchId.length;i++){
		document.getElementById(switchId[i]).className="";
	}
}
/*====================================================================================================

 HTMLに[小 中 大]の切り替えボタンを吐き出す。クッキーがあったらついでに実行。

====================================================================================================*/

function writeFontSizeSwitch(){
var fontsizeSwitch = document.createElement('div'); 
fontsizeSwitch.id  = "fontsize-switch";
fontsizeSwitch.innerHTML = yomotsuFontSizeSwitchConf.switchHTML; 

document.getElementById(yomotsuFontSizeSwitchConf.switchWriteArea).appendChild(fontsizeSwitch);

ifCookie();
}

if(window.addEventListener) {
	window.addEventListener("load", writeFontSizeSwitch, false);
}
else if(window.attachEvent) {
	window.attachEvent("onload", writeFontSizeSwitch);
}



/*====================================================================================================

 クッキーにセットする

====================================================================================================*/


function cookiePut(data) { 
	 limit = yomotsuFontSizeSwitchConf.cookieLimit;
	 name = yomotsuFontSizeSwitchConf.cookieName
 
	 today = new Date();
	 today.setTime(today.getTime()+1000*60*60*24*limit);
	 date = ';expires='+today.toGMTString();
 
	 document.cookie = name+'='+escape(data)+date;
}

/*====================================================================================================

 クッキーに記憶があればサイズ変更

====================================================================================================*/

function ifCookie(){
	var name = yomotsuFontSizeSwitchConf.cookieName;
	var cookie = document.cookie;
	
	if(cookie.indexOf(name) == -1){ //クッキーがなければデフォルト
		fontSizeSwitch("small");
	}
	else{
		var pos_s = cookie.indexOf(name)+name.length+1; //クッキーの値の開始位置
		var pos_e = cookie.indexOf(";",pos_s); //クッキーの値の終了位置
		if(pos_e == -1){ //末尾にセミコロンがあるか？
			var size = cookie.slice(pos_s); //無い
		}else{
			var size = cookie.slice(pos_s,pos_e); //有る
		}
	}
	
	fontSizeSwitch(size)

}



//alert(document.cookie)