// JavaScript Document


/* -------------------------------------------------- */
/* FontSize.js                                        */
/* -------------------------------------------------- */
/*
 1) body要素に「onload="SizeChange();"」を指定。
 　例）<body onload="SizeChange()">

 2) フォントサイズを変更したい要素に「id="wrapper"」と指定。※通常設定不要。
 （id名は下の「初期設定」で変更可能）
   例）<div id="wrapper">（～本文～）</div>

 3) ボタンを置きたい場所に<script type="text/javascript" src="FontSizeChange.js"></script>と記述。
*/

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

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

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

/* サイズの選択肢（指定できるのは数字のみ）*/
SizeList["S"] = 80;
SizeList["M"] = 95;
SizeList["L"] = 120;

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

/* テキストの表記 */
Text["S"] = "[小]";
Text["M"] = "[中]";
Text["L"] = "[大]";

/* テキストの色（上は選択していない色、下は選択中の色）*/
TextColor = 'black';
SelectedColor = 'gray';

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

/* 画像ボタン（未選択）設定 */
Img["S"] = 'http://www.kamei-tsusan.co.jp/img_common/btn_font-size_small_off.gif';
Img["M"] = 'http://www.kamei-tsusan.co.jp/img_common/btn_font-size_medium_off.gif';
Img["L"] = 'http://www.kamei-tsusan.co.jp/img_common/btn_font-size_large_off.gif';

/* 画像ボタン（選択中）設定 */
ImgOn["S"] = 'http://www.kamei-tsusan.co.jp/img_common/btn_font-size_small_on.gif';
ImgOn["M"] = 'http://www.kamei-tsusan.co.jp/img_common/btn_font-size_medium_on.gif';
ImgOn["L"] = 'http://www.kamei-tsusan.co.jp/img_common/btn_font-size_large_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('<img class="icon_size" src="' + ImgOn[Size] + '"> ');
		} else {
			document.write('<a href="javascript:Write(' + SizeList[Size] + ');"><img class="icon_size" 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) {
		Cookie = document.cookie;
		if (Cookie.match(/FontSize=([\d.]*)/)) {
			FontSize = RegExp.$1;
		}
	}
}

/* フォントサイズ変更 */
function SizeChange() {
	if (FontSize != null) {
		document.getElementById(Obj).style.fontSize = FontSize + 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;
	// 再読込
	location.reload();
}

