/*
===========================================================
フォントサイズ変更スクリプト
===========================================================
*/


/*
========== ::: 初期設定 ::: ==========
*/

// 値の単位を設定
var fontSizeUnit = "%";

// 初期状態の値を設定
var defaultSize = 90;

// クッキーの名前
var ckName = "FSCc";

// クッキーの有効期限（日）
var ckDays = 31;

// クッキーのパス
var ckPath = "/"

/*
========== ::: ページ読み込み時の値を設定 ::: ==========
*/

// クッキー読み出し
var fsCK = GetCookie( ckName );

if ( fsCK == null ){
  var currentSize = defaultSize;	//クッキーが無ければ現在の値を初期状態の値に設定
}
else{
  var currentSize = eval( fsCK );	//クッキーがあれば現在の値をクッキーの値に設定
}

//------ 以下標準サイズ  ------
//  paFSize = 80;
//  lnaFSize = 80; lnaLHSize = 120;
//  caFSize = 80;
//  hcaLHSize = 160;
//  caLHSize = 150;
//  raFSize = 80;
//  faFSize = 60;



if ( currentSize == 110 ){
  paFSize = 110;
  lnaFSize = 105;	lnaLHSize = 150;
  h2FSize = 110;		h2LHSize = 180;
  caFSize = 110;
  hcaLHSize = 190;
  caLHSize = 180;
  raFSize = 110;
  faFSize = 80;
} else if ( currentSize == 100 ){
  paFSize = 100;
  lnaFSize = 100;	lnaLHSize = 140;
  h2FSize = 100;	h2LHSize = 170;
  caFSize = 100;
  hcaLHSize = 180;
  caLHSize = 170;
  raFSize = 100;
  faFSize = 80;
} else {
  paFSize = 80;
  lnaFSize = 80;	lnaLHSize = 120;
  h2FSize = 80;		h2LHSize = 150;
  caFSize = 80;
  hcaLHSize = 160;
  caLHSize = 150;
  raFSize = 80;
  faFSize = 60;
}

/*
========== ::: head内にstyle要素を出力 ::: ==========
*/
document.writeln( '<style type="text/css">' );
document.writeln( '<!--' );
document.write( '.pankuzuArea { font-size:' + paFSize + '%; }' );
document.write( '.localNaviArea { font-size: ' + lnaFSize + '%; line-height: ' + lnaLHSize + '% }' );
document.write( '.h1_top h2  { font-size: ' + h2FSize + '%; line-height: ' + h2LHSize + '% }' );
document.write( '.contentsArea { font-size: ' + caFSize + '%; }' );
document.write( '* html .contentsArea { line-height: ' + hcaLHSize + '%; }' );
document.write( '.contentsArea { line-height: ' + caLHSize + '%; }' );
document.write( '.relatedArea { font-size:' + raFSize + '%; }' );
document.write( '.footerArea { font-size:' + faFSize + '%; }' );

document.writeln( '-->' );
document.writeln( '</style>' );

/*===================================
  [関数 fsc]
  引数CMDに渡される値に応じて
  変更後の値を算出しクッキーに書き込む。
====================================*/

function fsc( CMD ){

  // 大きい文字：デフォルト値110を値"newSize"に代入
  if ( CMD == "big" ){
    var newSize = 110;
    SetCookie( ckName , newSize );          //クッキー書き込み
  }

  // 通常の文字：デフォルト値100を値"newSize"に代入
  if ( CMD == "normal" ){
    var newSize = 100;
    SetCookie( ckName , newSize );          //クッキー書き込み
  }

  // 小さい文字：デフォルト値80を値"newSize"に代入
  if ( CMD == "little" ){
    var newSize = 80;
    SetCookie( ckName , newSize );          //クッキー書き込み
  }

  // 元に戻す：操作後の値を初期値にする
  if ( CMD == "default" ){
    DeleteCookie( ckName );          //クッキー削除
  }

  // ページの再読み込み
  // 再読み込みをすることで変更後の値を反映したstyle要素が出力される
  location.reload();
}

// _______________________________________ end of function fsc() ___ 


/*===================================
  [関数 SetCookie]
  クッキーに値を書き込む
====================================*/
function SetCookie( name , value ){
  var dobj = new Date();
  dobj.setTime(dobj.getTime() + 24 * 60 * 60 * ckDays * 1000);
  var expiryDate = dobj.toGMTString();
  document.cookie = name + '=' + escape(value) + ';expires=' + expiryDate + ';path=' + ckPath;
}

/*===================================
  [関数 GetCookie]
  クッキーを取得する
====================================*/
function GetCookie (name){
  var arg  = name + "=";
  var alen = arg.length;
  var clen = document.cookie.length;
  var i = 0;
  while (i < clen){
    var j = i + alen;
    if (document.cookie.substring(i, j) == arg)
    return getCookieVal (j);
    i = document.cookie.indexOf(" ", i) + 1;
    if (i == 0) break;
  }
  return null;
}

/*===================================
  [関数 getCookieVal]
  クッキーの値を抽出する
====================================*/
function getCookieVal (offset){
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1)
  endstr = document.cookie.length;
  return unescape(document.cookie.substring(offset,endstr));
}

/*===================================
  [関数 DeleteCookie]
  クッキーを削除する
====================================*/
function DeleteCookie(name){
  if (GetCookie(name)){
    document.cookie = name + '=' +
    '; expires=Thu, 01-Jan-70 00:00:01 GMT;path='+ckPath;
  }
}


/*===================================
  [関数 setFontImg]
  文字サイズ変更用画像を設定する
  設定外の値の場合はデフォルトで対処
  flgの値でフォルダ構成を設定する
  "0" = "./img/"
  "1" = "../img/"
  "2" = "../../img/"
  "3" = "../../../img/"
====================================*/
function setFontImg(flg) {
  var flgArray = Array("./", "../", "../../", "../../../");
  var imgName = null;
  var imgStr = new Image();

  if(currentSize == "110") {
    imgName = "fontmenu03";
    imgStr.src = flgArray[flg] + "common/img/button_large_on.gif";
  } else if(currentSize == "100") {
    imgName = "fontmenu02";
    imgStr.src = flgArray[flg] + "common/img/button_middle_on.gif";
  } else if(currentSize == "90") {
    imgName = "fontmenu01";
    imgStr.src = flgArray[flg] + "common/img/button_small_on.gif";
  } else {
    imgName = "fontmenu01";
    imgStr.src = flgArray[flg] + "common/img/button_small_on.gif";
  }
  document.images[imgName].src = imgStr.src;
}

//EOF