/*
*	※Licence: CC3.0 
*	http://creativecommons.org/licenses/by/3.0/deed.ja
*
*	Title: Layout Changer for Vicuna v1.1
*	URI: http://10coin.com/products/layout-changer/
*	Last Modified: 2007-11-067
*	Author: marble
*/

var fontSizeSwitcher = {
    str: '',
    config: {
        area: ['user','top-area','page','footer'],
        length: 3,
        id: ['fontSizeSwitcherSmall', 'fontSizeSwitcherMedium', 'fontSizeSwitcherLarge'],
        label: ['S', 'M', 'L'],
        size: ['100%', '108%', '116%'],
        cookieName: 'keiyuFontSize',
        cookieDate: 90
    },

    changeFontSize: function(size) {
        var config = this.config;
        var items  = document.getElementById('fontchange').getElementsByTagName("a");

        for(var i = 0, l = items.length; i < l ; i++) {
            if(size == i) {
                this.setClassName(items[i], 'current');
            }
            else {
                this.setClassName(items[i], 'def');
            }
        }

        var ss = document.styleSheets[0];

        for(var i = 0, l = config.area.length; i < l; i++) {
            //if(document.fileModifiedDate) {
            if(window.clipboardData) {
                ss.addRule('#' + config.area[i], 'font-size: ' + config.size[size]  + ';');
            }
            else {
                ss.insertRule('#' + config.area[i] + '{ font-size: ' + config.size[size]  + '; }', ss.cssRules.length);
            }
        }

        // set cookie
        this.setCookie(size);
    },

    setCookie: function(data) {
        var t = new Date();
        t.setTime(t.getTime() + (1000 * 60 * 60 * 24 * Number(this.config.cookieDate)));
        document.cookie = this.config.cookieName + '=' + encodeURIComponent(data) + '; path=/; expires=' + t.toGMTString();
    },

    getCookie: function(m) {
        return (m = ('; ' + document.cookie + ';').match('; ' + this.config.cookieName + '=(.*?);')) ? decodeURIComponent(m[1]) : null;
    },

    setClassName: function(elem, str) {
            //if(document.fileModifiedDate) {
            if(window.clipboardData) {
                elem.className = str;
            }
            else {
                elem.setAttribute('class', str);
            }
    },

    removeClassName: function(elem) {
            //if(document.fileModifiedDate) {
            if(window.clipboardData) {
                elem.removeAttribute('className');
            }
            else {
                elem.removeAttribute('class');
            }
    },

    start: function() {
        var target = this;
        var config = this.config;
        var size   = this.getCookie('s');

        for(var i = 0, l = config.length; i < l ; i++) {
            this.str += '<dd id="' + config.id[i] + '"><a href="javascript:;" onclick="fontSizeSwitcher.changeFontSize(' + i + '); return false;">' + config.label[i] + '</a></dd>';
        }

        document.write('<dl id="fontchange"><dt><img src="http://www.keiyu-hospital.com/images/template/size.gif" alt="文字サイズ変更" width="81" height="11" /></dt>' + this.str + '</dl>');

        if(size == null) {
            size = 0;
        }

        this.changeFontSize(size)
    }
}

fontSizeSwitcher.start();

