var fontSizeSwitcher = {
    str: '',
    config: {
		area: ['right','right2','contentsbox'],				//div#right
        size: ['80%', '100%', '120%'], // 切り替えサイズ
        Hiconlocation: ['0 10px', '0 12px', '0 14px'], // Htag adjust
		lineheight: ['142%', '140%', '131%'], 
        cookieName: 'imageHD', // ここにクッキー名を入れる
        cookieDate: '30' // クッキーの有効日数
    },
    cookie: {
        set: function(n, v) {
            var t = new Date();
            t.setTime(t.getTime() + (1000 * 60 * 60 * 24 * fontSizeSwitcher.config.cookieDate));
            document.cookie = n + '=' + encodeURIComponent(v) + '; path=/; expires=' + t.toGMTString();
        },
        get: function(n, m) {
            return (m = ('; ' + document.cookie + ';').match('; ' + n + '=(.*?);')) ? decodeURIComponent(m[1]) : '';
        }
    },
    changeFontSize: function(i) {
        var config = this.config;
        //document.body.style.fontSize = config.size[i];
		
		for (j=0; j<config.area.length; j++){
			if (document.getElementById(config.area[j])) {
				document.getElementById(config.area[j]).style.fontSize = config.size[i];
				document.getElementById(config.area[j]).style.lineHeight = config.lineheight[i];
			}
		}
		
		//tag adjust
		h3param = document.getElementsByTagName("H3");
		for (j=0; j<h3param.length; j++)
		{ 
			h3param[j].style.backgroundPosition = config.Hiconlocation[i];// H3iconlocation
		}
		
		h4param = document.getElementsByTagName("H4");
		for (j=0; j<h4param.length; j++)
		{ 
			h4param[j].style.backgroundPosition = config.Hiconlocation[i];// H4iconlocation
		}

		h5param = document.getElementsByTagName("H5");
		for (j=0; j<h5param.length; j++)
		{ 
			h5param[j].style.backgroundPosition = config.Hiconlocation[i];// H5iconlocation
		}

        // set cookie
        this.cookie.set(config.cookieName, i);
        
        // set images
		var divs = document.getElementsByTagName("div");
		var result = new Array();
		/* div要素のひとつずつclass名を確認していく */
		for (procnum=0; procnum < divs.length; procnum++){
			if (divs.item(procnum).className == 'fontsizesw'){
				/* class名が--なら、配列resultにdiv要素を追加していく */
				result.push(divs[procnum]);
			}
		}

		fontsizeul = result[0].getElementsByTagName("ul"); //document.getElementById("fontsizesw");
        fontsizelis = fontsizeul[0].getElementsByTagName("li");

		urabase = 'http://www.image-hd.co.jp/';

        fontsizelis[0].innerHTML = '<a href="javascript:fontSizeSwitcher.changeFontSize(0);" title="S"><img src="' + urabase + 'images/fontsizesw_S.gif" alt="S" width="29" height="24" /></a>';
        fontsizelis[1].innerHTML = '<a href="javascript:fontSizeSwitcher.changeFontSize(1);" title="M"><img src="' + urabase + 'images/fontsizesw_M.gif" alt="M" width="31" height="25" /></a>';
        fontsizelis[2].innerHTML = '<a href="javascript:fontSizeSwitcher.changeFontSize(2);" title="L"><img src="' + urabase + 'images/fontsizesw_L.gif" alt="L" width="31" height="27" /></a>';
		
		},
    start: function() {
        var config = this.config;
        var i      = this.cookie.get(config.cookieName, 's');

        if(i == '') i = 1;
        try {
            window.addEventListener("load", function() {
                fontSizeSwitcher.changeFontSize(i)
            }, false);
        }
        catch(e) {
            window.attachEvent("onload", function() {
                fontSizeSwitcher.changeFontSize(i)
            });
        }
    }
}
fontSizeSwitcher.start();

