var fontSizeSwitcher = {
    str: '',
    config: {
        area: ['main'], // 対象となるid
        length: 3, // 切り替え段階数
        id: ['fontSizeSwitcherSmall', 'fontSizeSwitcherMedium', 'fontSizeSwitcherLarge'], // 切り替えボタンの各id
        label: ['<img src="http://www.secondlife-info.com/images/mojisize02.gif" alt="" width="50" height="19" />', '<img src="http://www.secondlife-info.com/images/mojisize03.gif" alt="" width="49" height="19" />', '<img src="http://www.secondlife-info.com/images/mojisize04.gif" alt="" width="51" height="19" />'], // 切り替えボタンの各ラベル
        size: ['80%', '100%', '120%'], // 切り替えサイズ
        cookieName: 'sawafontsize', // ここにクッキー名を入れる
        cookieDate: '90' // クッキーの有効日数
    },

    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;

        var items = document.getElementById('fontSizeSwitcher').childNodes;
        for(var j = 0; j < items.length; j++) {
            if(i == j) {
                items[j].setAttribute('class', 'current');
            }
            else {
                items[j].removeAttribute('class');
            }
        }

        for(var j = 0, l = config.area.length; j < l; j++) {
            document.getElementById(config.area[j]).style.fontSize = config.size[i];
        }

        // set cookie
        this.cookie.set(config.cookieName, i);
    },

    start: function() {
        var config = this.config;
        var i      = this.cookie.get(config.cookieName, 's');

        for(var j = 0; j < config.length; j++) {
            this.str += '<span id="' + config.id[j] + '" onclick="fontSizeSwitcher.changeFontSize(' + j + ')">' + config.label[j] + '</span>';// ここボタンの入るところのソース
        }

        document.write('<div id="fontSizeSwitcher">' + this.str + '</div>');//ここは上記ソースをはさむタグ

        if(i == '') {
            i = 1;
        }

        try {
            window.addEventListener("load", function() {
                fontSizeSwitcher.changeFontSize(i)
            }, false);
        }
        catch(e) {
            window.attachEvent("onload", function() {
                fontSizeSwitcher.changeFontSize(i)
            });
        }
    }
}

fontSizeSwitcher.start();