﻿// SwitchFontsize ----------------------------------------

var contentSwitchFontSize = {
conf : {
fontSize     : ["115%","100%","85%"],
switchId     : ["switchFontSizeBig", "switchFontSizeMedium", "switchFontSizeSmall"],
defoSizeId   : "switchFontSizeMedium",
targetAreaId : "contents",
cookieName   : "FontSizeChange",
cookieLimit  : 30,
switchWriteArea : "font-change",
switchHTML      : '<ul><li id="switchFontSizeSmall" style="text-indent:-9999px;"><span>小</span></li><li id="switchFontSizeMedium" style="text-indent:-9999px;"><span>標準</span></li><li id="switchFontSizeBig" style="text-indent:-9999px;"><span>大</span></li></ul>'
},
main : function(){
contentSwitchFontSize.setHTML();
contentSwitchFontSize.defo();
var i, j, switchItem = contentSwitchFontSize.conf.switchId;
for(i=0;i<switchItem.length;i++){
document.getElementById(switchItem[i]).onclick = contentSwitchFontSize.action;
}
},
setHTML : function(){
var fontsizeSwitch = document.createElement('div');
fontsizeSwitch.id  = "fontsizeControl";
fontsizeSwitch.innerHTML = contentSwitchFontSize.conf.switchHTML;
document.getElementById(contentSwitchFontSize.conf.switchWriteArea).appendChild(fontsizeSwitch);
},

defo : function(){
var i;
var switchId = contentSwitchFontSize.conf.switchId;
var targetAreaId = contentSwitchFontSize.conf.targetAreaId;
var fontSize = contentSwitchFontSize.conf.fontSize;
cookieValue = this.getCookie() || contentSwitchFontSize.conf.defoSizeId;
for(i = 0; i < switchId.length; i++){
if(cookieValue == switchId[i]){
document.getElementById(targetAreaId).style.fontSize = fontSize[i];
}
}
document.getElementById(cookieValue).className ="active";
},
action : function(){
var i;
var switchId = contentSwitchFontSize.conf.switchId;
var targetAreaId = contentSwitchFontSize.conf.targetAreaId
var fontSize = contentSwitchFontSize.conf.fontSize
for(i=0;i<switchId.length;i++){
var switchItem = document.getElementById(switchId[i]);
switchItem.className="";
if(this.id == switchId[i]){
document.getElementById(targetAreaId).style.fontSize = fontSize[i];
}
}
this.className ="active";
contentSwitchFontSize.setCookie(this.id);
},
setCookie: function(data) {
var today = new Date();
today.setTime(today.getTime() + (1000 * 60 * 60 * 24 * Number(this.conf.cookieLimit)));
document.cookie = this.conf.cookieName + '=' + encodeURIComponent(data) + '; path=/; expires=' + today.toGMTString();
},
getCookie: function(m) {
return (m = ('; ' + document.cookie + ';').match('; ' + this.conf.cookieName + '=(.*?);')) ? decodeURIComponent(m[1]) : null;
}
}
Event.observe(window, "load", contentSwitchFontSize.main, false);

