/**************************************************************************************
fontsizachanger.js
***************************************************************************************/

//基本設定

	//対象となる要素のID属性
	fontSizeChangeArea = "container"

	//デフォルトの文字サイズ
	var defaultFontSize = "80%"

	//文字の拡大率
	var enlargeFontSize = "10%"

	//文字の縮小率
	var reduceFontSize = "5%"

	//最大文字サイズ
	var maxFontSize = "110%"

	//最小文字サイズ
	var minimumFontSize = "65%"

var defaultFontSize = parseInt(defaultFontSize);
var enlargeFontSize = parseInt(enlargeFontSize);
var reduceFontSize = parseInt(reduceFontSize);
var maxFontSize = parseInt(maxFontSize);
var minimumFontSize = parseInt(minimumFontSize);



//文字サイズの変更
function fontSizeChange(size){
	//文字を大きくする
	if(size == "large"){
		tag = document.getElementById(fontSizeChangeArea);

		fontSize = tag.style.fontSize;
		if(fontSize == ""){fontSize = defaultFontSize;}
		fontSize = parseInt(fontSize);

		if(maxFontSize > fontSize && fontSize >= defaultFontSize){
			tag.style.fontSize = fontSize + enlargeFontSize + "%";
		}else if(fontSize < defaultFontSize){
			tag.style.fontSize = fontSize + reduceFontSize + "%";
		}else{
			alert("これ以上大きくなりません");
		}
		setCookie();
	}

	//文字を小さくする
	if(size == "small"){
		tag = document.getElementById(fontSizeChangeArea);

		fontSize = tag.style.fontSize;
		if(fontSize == ""){fontSize = defaultFontSize;}
		fontSize = parseInt(fontSize);

		if(minimumFontSize < fontSize && fontSize <= defaultFontSize){
			tag.style.fontSize = fontSize - reduceFontSize + "%"
		}else if(fontSize > defaultFontSize){
			tag.style.fontSize = fontSize - enlargeFontSize + "%"
		}else{
			alert("これ以上小さくなりません");
		}
		setCookie();
	}

	//文字を標準に戻す
	if(size == "medium"){
		tag = document.getElementById(fontSizeChangeArea);
		tag.style.fontSize = defaultFontSize + "%";
		setCookie();
	}
}


//サイズ変更後cookieにサイズ保存
function setCookie(){
	var tag = document.getElementById(fontSizeChangeArea);
	var fontSize = tag.style.fontSize;
	document.cookie = fontSize;
}
//ページ読み込み時にデフォルトフォントサイズ変更
function setDefaultFontSize(){
	var tag = document.getElementById(fontSizeChangeArea);
	tag.style.fontSize = document.cookie;
}

// 複数onload対応
function addOnloadEvent(func){
	var oldonload = window.onload;
	if(typeof oldonload != "function"){
		window.onload = func;
	}else{
		window.onload = function(){
			oldonload();
			func();
		}
	}
}
addOnloadEvent(setDefaultFontSize);

