// フォントサイズ変更スクリプト

// 名前空間定義
var com = window.com = window.com || {};
com.ongakuza_musical = com.ongakuza_musical || {};
com.ongakuza_musical.font = com.ongakuza_musical.font || {};
var here = com.ongakuza_musical.font;

// 識別子定義
var ID = here.ID = "FontSize";

// 定数オブジェクト
var FontSize = here.FontSize = function(sizeName, size){
	this.name = sizeName;
	this.size = size;
};
FontSize.prototype.toString = function(){
	return this.name;
};
FontSize = here.FontSize = {Small: new FontSize("Small", "50%"), Normal: new FontSize("Normal", "62.5%"), Big: new FontSize("Big", "100%")};

// Cookie操作用
var setCookie = here.setCookie = function(name, value, expires){
	document.cookie = name + "=" + value + ";expires=" + expires.toGMTString() + ";path=/;";
};
var getCookie = here.getCookie = function(name){
	var cookieFullString = document.cookie + ";";
	var namePoint = cookieFullString.indexOf(name);
	if(namePoint < 0) return null;
	var splitPoint = cookieFullString.indexOf("=", namePoint) + 1;
	var endPoint = cookieFullString.indexOf(";", splitPoint);
	return cookieFullString.substring(splitPoint, endPoint);
}

// フォントサイズ操作
var setFontSize = here.setFontSize = function(fontSize){
											document.body.style.fontSize = fontSize.size;
											var ex  = new Date();
											ex.setTime(ex.getTime() + 30*24*60*60*1000);
											setCookie(ID, fontSize.name, ex);
};

// DOM操作用。クラスを消去
var clearNowSize = here.clearNowSize = function(){
	var lists = ["small", "normal", "big"];
	for(var i = lists.length - 1; i > -1; i--){
		document.getElementById(lists[i]).className = "";
	}
};

(function(){
	var here = com.ongakuza_musical.font;
	var size =  here.getCookie(ID);
	if(size){
		here.setFontSize(here.FontSize[size]);
		here.clearNowSize();
		document.getElementById(size.toString().toLowerCase()).className = "now";
	}
})();
