/* FontSizeChange */

/* ----------------- 変数宣言 -------------------*/
var ButtonType;
var FontSize;
var Unit;
var Obj,Obj2,Obj3;
var LinkColor;
var SelectedColor;
var SelectedBold;
Img = new Array();
ImgOn = new Array();
SizeList = new Array();
SizeList2 = new Array();
Units = new Array('%','px','pt','em');
Text = new Array();

/* ----------------- 初期設定 -------------------*/
/* IDの指定 */
//文字サイズを変更したい要素のID
Obj = 'header';
Obj2 = 'contents';
Obj3 = 'footer';

/* サイズの単位（0 = %、1 = px、2 = pt, 3= em） */
Unit = 2;

/* サイズの選択肢（上から順に小、中、大。指定できるのは数字のみ）*/
SizeList["S"] = 8;
SizeList["M"] = 10;
SizeList["L"] = 12;

/* ボタンのタイプ （0 = テキスト  1 = 画像）*/
ButtonType = 1;

/* テキストの表記（上から順に小、中、大）*/
Text["S"] = "[小]";
Text["M"] = "[中]";
Text["L"] = "[大]";

/* テキストの色（上は選択していないサイズ、下は選択中のサイズ）*/
TextColor = 'blue';
SelectedColor = 'red';

/* 選択中のサイズの太字表記（0 = 普通、 1 = 太字） */
SelectedBold = 0; 

/* 画像ボタン（未選択）のURL（上から順に小、中、大）*/
Img["S"] = '/images/common/s.gif';
Img["M"] = '/images/common/m.gif';
Img["L"] = '/images/common/l.gif';

/* 画像ボタン（選択中）のURL（上から順に小、中、大）*/
ImgOn["S"] = '/images/common/s_on.gif';
ImgOn["M"] = '/images/common/m_on.gif';
ImgOn["L"] = '/images/common/l_on.gif';

/* Cookieの有効期限（日数） */
ExpireDays = 30;


/* -------------------- 実　行 ---------------------*/
ReadCookie();
Buttons();


/* -------------------- 関　数 ---------------------*/
/* ボタン書き出し */
function Buttons() {
	Button("S");
	Button("M");
	Button("L");
}

/* 各ボタンの書き出し */
function Button(Size) {
	// 画像
	if (ButtonType) {
		if (SizeList[Size] == FontSize) {
			document.write('<a><img src="' + ImgOn[Size] + '"></a> ');
		} else {
			document.write('<a href="javascript:Write(' + SizeList[Size] + ');"><img src="' + Img[Size] + '" border=0"></a> ');
		}
	// テキスト
	} else {
		if (SizeList[Size] == FontSize) {
			var Style;
			if (SelectedBold) {
				Style = 'color:' + SelectedColor + ';font-weight:bold';
			} else {
				Style = 'color:' + SelectedColor;
			}
			document.write ('<span style="' + Style + '">' + Text[Size] + '</span> ');
		} else {
			document.write ('<a href="javascript:Write(' + SizeList[Size] + ');" style="color:' + TextColor + '">' + Text[Size] + '</a> ');
		}
	}
}

/* Cookie呼出 */
function ReadCookie() {
	if (!document.cookie) {
		Write(SizeList["M"])
	}
	Cookie = document.cookie;
	if (Cookie.match(/FontSize=([\d.]*)/)) {
		FontSize = RegExp.$1;
	}else{
		FontSize = SizeList["M"];
	}
}

/* フォントサイズ変更 */
function SizeChange() {
	if (FontSize != null) {
		document.getElementById(Obj).style.fontSize = FontSize + Units[Unit];
		document.getElementById(Obj2).style.fontSize = FontSize + Units[Unit];
		$("table").css("font-size", FontSize + Units[Unit]);
		if(navigator.userAgent.indexOf("MSIE") != -1){ // 文字列に「MSIE」が含まれている場合
			document.getElementById(Obj3).style.fontSize = (FontSize - 3.5) + Units[Unit];
		}else{
			document.getElementById(Obj3).style.fontSize = (FontSize - 2) + Units[Unit];
		}
	}
}

/* Cookie書込 */
function Write(Size) {
	// 日付の計算
	var toDay = new Date;
	var xDay = new Date;
	parseInt(ExpireDays);
	xDay.setDate(toDay.getDate()+ExpireDays);
	ExpireText = xDay.toGMTString();
	// 書込
	document.cookie = "FontSize = " + Size + ";expires=" + ExpireText + ";path=/";
	// 再読込
	location.reload();
}
