/* *** ▼初期設定 *** */

//13÷16
if (typeof document.documentElement.style.maxHeight != "undefined") {
	//IE7以上のモダンブラウザ
	var defaultFontSize = 81.25;
	var fontselect = '"ヒラギノ角ゴ Pro W3","Hiragino Kaku Gothic Pro","メイリオ","Meiryo","ＭＳ Ｐゴシック","MS P Gothic",sans-serif;';
	//IE7以上のモダンブラウザでXP
	if (navigator.userAgent.indexOf("NT 5.1")>=0) {
		var fontselect = '"ＭＳ Ｐゴシック","MS P Gothic",sans-serif;';
	}
}
else {
	//IE6以下、その他
	var defaultFontSize = 81.25;
	var fontselect = '"ＭＳ Ｐゴシック","MS P Gothic",sans-serif;';
}

//フォントサイズ（単位）の設定
var unit = "%";

//1回の変更で増減する値（%）
var diff = 5;

//クッキー名称
var cookieName = "STEREOPIPE_FONT_SIZE";

//クッキーの有効期限（日数）
var cookieExpiresDay = 30;
	
/* *** ▼読み込み時の設定 *** */

//クッキー取得
var ck = readCookie(cookieName);

//クッキーなし
if(ck == null){
  currentFontSize = defaultFontSize;
//クッキーあり
}else{
  currentFontSize = Number(ck);
}

document.writeln( '<style type="text/css" media="all">' );
document.write( 'body {font-size:' + currentFontSize + unit+ '; font-family:' + fontselect + ';}' );
document.writeln( '</style>' );

/* ============================================
  function: setCookie
  クッキーをセット
=============================================== */

function setCookie(name,value){
  var sday = new Date();
  sday.setTime(sday.getTime() + 24 * 60 * 60 * cookieExpiresDay * 1000);
  var s2day = sday.toGMTString();
  //クッキーをセット
  document.cookie = name + '=' + escape(value)+ ';expires=' + s2day + ';path=/';
}

/* ============================================
  function: readCookie
  クッキーを読み込む
=============================================== */
	
function readCookie(name){
  var arg  = name + "=";
  var argLen = arg.length;
  var cookieLen = document.cookie.length;
  var i = 0;
  while (i < cookieLen){
    var j = i + argLen;
    if (document.cookie.substring(i, j) == arg){
    	var end = document.cookie.indexOf (";", j);
  		if(end == -1)
  		end = document.cookie.length;
  		return unescape(document.cookie.substring(j,end));
    }
    i = document.cookie.indexOf(" ", i) + 1;
    if (i == 0) break;
  }
   return null;
}

/* ============================================
  function: delCookie
  クッキーを削除する
=============================================== */
	
function delCookie(name){
  if (readCookie(name)) {
    document.cookie = name + '=' + '; expires=Thu, 01-Jan-70 00:00:01 GMT;path=/';
  }
}

/* ============================================
  function: fontSizeChange
  bodyのfontSizeをcurrentFontSizeに設定
=============================================== */

function fontSizeChange(){
  	//bodyのfontSizeを変更
    document.body.style.fontSize = currentFontSize + unit;
}

/* ============================================
  function: fontSizeSetCookie
  引数("larger" or "smaller")
  変更後の値をクッキーに書き込む
=============================================== */

function fontSizeSetCookie(mode){

  //フォントサイズ拡大
  if(mode == "larger"){
    var newFontSize = Number(currentFontSize + diff);
    setCookie(cookieName,newFontSize);
  }

  //フォントサイズ縮小
  if( mode == "smaller" ){
    if (currentFontSize != diff){
      var newFontSize = Number(currentFontSize - diff);
      setCookie(cookieName,newFontSize);
    }else{
      var newFontSize = Number(currentFontSize);
    }
  }

  //フォントサイズを初期値に戻す
  if( mode == "default" ){
    var newFontSize = defaultFontSize;
    //クッキー削除
    delCookie(cookieName);
  }

  //現在のフォントサイズを変更後の値に設定
  currentFontSize = newFontSize;

  //bodyのfontSizeを変更
  fontSizeChange();

}