var yomotsuSwitchFontSize = {
	
	conf : {
		fontSize    : ["1.2em","1.1em","1em"],
		switchId    : ["switchFontSizeBig", "switchFontSizeMedium", "switchFontSizeSmall"],
		defoSizeId  : "switchFontSizeSmall",
		targetAreaId: "container",              //フォントサイズを適用するエリアのID
		cookieName  : "yomotsuFontSize",      //クッキーの名前
		cookieLimit : 30,                     //有効期限(日にち)
		switchWriteArea : "size",          //指定したIDのエリアの一番最後にスイッチのHTMLが書き込まれる
		switchHTML      : ''

// switchHTMLの参考用デフォルト値
//
//  <ul>
//  <li id="switchFontSizeBig">大</li>
//  <li id="switchFontSizeMedium">中</li>
//  <li id="switchFontSizeSmall">小</li>
//  </ul>

	},
	
	main : function(){
		yomotsuSwitchFontSize.setHTML();
		yomotsuSwitchFontSize.defo();
		var i, j, switchItem = yomotsuSwitchFontSize.conf.switchId;
		
		for(i=0;i<switchItem.length;i++){
			document.getElementById(switchItem[i]).onclick = yomotsuSwitchFontSize.action;
		}
	},
	
	setHTML : function(){
		var fontsizeSwitch = document.createElement('h6'); 
		fontsizeSwitch.id  = "fontsizeControl";
		fontsizeSwitch.innerHTML = yomotsuSwitchFontSize.conf.switchHTML; 
		
		document.getElementById(yomotsuSwitchFontSize.conf.switchWriteArea).appendChild(fontsizeSwitch);
	},
	
	defo : function(){
		var i;
		var switchId = yomotsuSwitchFontSize.conf.switchId;
		var targetAreaId = yomotsuSwitchFontSize.conf.targetAreaId;
		var fontSize = yomotsuSwitchFontSize.conf.fontSize;
		
		cookieValue = this.getCookie() || yomotsuSwitchFontSize.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 = yomotsuSwitchFontSize.conf.switchId;
		var targetAreaId = yomotsuSwitchFontSize.conf.targetAreaId
		var fontSize = yomotsuSwitchFontSize.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";
		
		yomotsuSwitchFontSize.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;
	},
	
	addEvent : function(){
		if(window.addEventListener) {
			window.addEventListener("load", this.main, false);
		}
		else if(window.attachEvent) {
			window.attachEvent("onload", this.main);
		}
	}
	
}

yomotsuSwitchFontSize.addEvent();

//＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝
//　コピーライト 「年」表示の自動更新
//＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝
function ShowNowYear() {
   var now = new Date();
   var year = now.getFullYear();
   document.write(year);
}

/*
	Standards Compliant Rollover Script
	Author : Daniel Nolan
	http://www.bleedingego.co.uk/webdev.php
*/

function initRollovers() {
	if (!document.getElementById) return
	
	var aPreLoad = new Array();
	var sTempSrc;
	var aImages = document.getElementsByTagName('img');

	for (var i = 0; i < aImages.length; i++) {		
		if (aImages[i].className == 'imgover') {
			var src = aImages[i].getAttribute('src');
			var ftype = src.substring(src.lastIndexOf('.'), src.length);
			var hsrc = src.replace(ftype, '_o'+ftype);

			aImages[i].setAttribute('hsrc', hsrc);
			
			aPreLoad[i] = new Image();
			aPreLoad[i].src = hsrc;
			
			aImages[i].onmouseover = function() {
				sTempSrc = this.getAttribute('src');
				this.setAttribute('src', this.getAttribute('hsrc'));
			}	
			
			aImages[i].onmouseout = function() {
				if (!sTempSrc) sTempSrc = this.getAttribute('src').replace('_o'+ftype, ftype);
				this.setAttribute('src', sTempSrc);
			}
		}
	}
}

window.onload = initRollovers;
