if (typeof(QLife) == 'undefined') {
    var QLife = {};
}

QLife.Fontsize = {
    /**
     * フォントサイズ変更<a>のid属性値
     */
    ANCHORS_ID : ['fontsize1', 'fontsize2', 'fontsize3'],
    /**
     * 現在選択中を示すclass値
     */
    CLASSNAME_ACTIVE : 'active',
    /**
     * フォントサイズ: 小
     */
    SIZE_S : 1,
    /**
     * フォントサイズ: 中
     */
    SIZE_M : 2,
    /**
     * フォントサイズ: 大
     */
    SIZE_L : 3,
    /**
     * フォントサイズを変更する
     *
     * @param int    fontsize       フォントサイズ(1-3)
     * @param string activeAnchorId アクティブにする<a>タグのid属性値
     */
    update : function(fontsize, activeAnchorId){
        // フォントサイズの決定
        var size1 = '', size2 = '', size3 = '';
        switch (fontsize) {
        case this.SIZE_S:
            size1 = '13px'; size2 = '13px'; size3 = '15px';
            break;
        case this.SIZE_M:
            size1 = '13px'; size2 = '15px'; size3 = '17px';
            break;
        case this.SIZE_L:
            size1 = '15px'; size2 = '17px'; size3 = '19px';
            break;
        }
        // フォントサイズの更新
        var elements = $$('body, th, td, h1, h2, h3, h4, h5, *.size1, *.size2, *.size3');
        for (var k = 0, length2 = elements.length ; k < length2 ; k++) {
            var e = elements[k];
            if (e.hasClassName('size1')) {
                e.setStyle({fontSize : size1});
            } else if (e.hasClassName('size3')) {
                e.setStyle({fontSize : size3});
            } else {
                e.setStyle({fontSize : size2});
            }
        }
        // アイコンのスタイル変更
        for (var i = 0, length = this.ANCHORS_ID.length ; i < length ; i++) {
            var e = $(this.ANCHORS_ID[i]);
            if (e == null) {
                alert('id=' + this.ANCHORS_ID[i] + ' does not exist.');
            } else {
                e.removeClassName(this.CLASSNAME_ACTIVE);
            }
        }
        $(activeAnchorId).addClassName(this.CLASSNAME_ACTIVE);
        // Cookieにフォントサイズ設定を保存
        new Ajax.Request('/2008qlife_lib/fontsize_update.php', {
            method : 'get',
            parameters : {size : fontsize}
        });
    }
}
