/*------------------------------------------------------------
  TextSizeController Ver 1.1
  [http://www.trustworks.biz/]
--------------------------------------------------------------
  [2008/04/26] クッキー有効範囲のPath設定を追加
------------------------------------------------------------*/
var TextSizeController = {

/* プロパティ
============================================================*/
//使用テキストサイズ単位
tsUnit:"px",
//標準テキストサイズ
normalSize: 14,
//小サイズ
smallSize: 12,
//大サイズ
bigSize: 16,
//変更単位サイズ
unitSize: 2,
//クッキー名
cookieName:"tsc",
//クッキー有効期限（日数）
cookieExpDay:1,
//クッキー無効時のアラートメッセージ
cookieOffMsg:"Cookieを有効にして下さい。",
//クッキー有効範囲
cookiePath:"/",


/* bodyオブジェクト
============================================================*/
bodyObj:function(){
return document.getElementsByTagName('body')[0];
},


/* クッキー取得
============================================================*/
getCookie:function(){
var cd = document.cookie.split("; ");
for(var i=0;i<cd.length;i++){
if(cd[i].indexOf(this.cookieName + "=")>=0){
var latestSetting = cd[i].split("=")[1];
return latestSetting;
}
}
return false;
},


/* クッキー書込み
============================================================*/
writeCookie:function(value){
var ce = new Date();
ce.setTime(ce.getTime() + (this.cookieExpDay*24*60*60*1000));
document.cookie = this.cookieName + "=" + value + "; expires=" + ce.toGMTString() + "; path=" + this.cookiePath;
},


/* クッキー使用確認
============================================================*/
checkCookie:function(){
if(!navigator.cookieEnabled){
alert(this.cookieOffMsg);
return false;
}
return true;
},


/* サイズ変更
============================================================*/
sizeControl:function(key){
//クッキー使用確認実行
this.checkCookie();
var latestSize = parseInt(this.bodyObj().style.fontSize);
(key=="+")?latestSize=this.bigSize:latestSize=this.smallSize;
this.bodyObj().style.fontSize = latestSize + this.tsUnit;
//クッキー書込み実行
this.writeCookie(latestSize);
return false;
},


/* サイズリセット
============================================================*/
sizeReset:function(){
//クッキー使用確認実行
this.checkCookie();
this.bodyObj().style.fontSize = this.normalSize + this.tsUnit;
//クッキー書込み実行
this.writeCookie(this.normalSize);
},


/* 初期設定
============================================================*/
init:function(){
var bodyStyle = this.bodyObj().style;
//クッキーが存在する
if(this.getCookie()){
bodyStyle.fontSize = this.getCookie() + this.tsUnit;
}
//クッキーが存在しない
else{
bodyStyle.fontSize = this.normalSize + this.tsUnit;
}
}
};


/* イベント設定
============================================================*/
function setEventTSC(){
var anchorObj = document.getElementsByTagName('a');
for(var i=0;i<anchorObj.length;i++){
if(anchorObj[i].className.match("btnBig")){
anchorObj[i].onclick = function(){
TextSizeController.sizeControl('+');
return false;
};
}else if(anchorObj[i].className.match("btnSmall")){
anchorObj[i].onclick = function(){
TextSizeController.sizeControl('-');
return false;
};
}else if(anchorObj[i].className.match("btnMiddle")){
anchorObj[i].onclick = function(){
TextSizeController.sizeReset();
return false;
};
}
}
//初期設定実行
TextSizeController.init();
}


/* イベント設定実行
============================================================*/
if(window.addEventListener){
window.addEventListener("load",setEventTSC,false);
}else if(window.attachEvent){
window.attachEvent("onload",setEventTSC);
}

