﻿// FlucutatePageClass.js
// Changes 'body' class name

var FluctuatePageClass = Class.create({
    initialize: function(opts) {
        this.inc = 1;
        this.nameSpace = 'textSize';
        this.max = 5;
        if (opts) {
            if (opts.start) {
                this.inc = opts.start;
                this.setClass();
            }
            if (opts.max) {
                this.max = opts.max;
            }
        }
    },
    removeClass: function() {
        $$('body')[0].removeClassName(this.nameSpace + this.inc);
    },
    setClass: function() {
        $$('body')[0].addClassName(this.nameSpace + this.inc);
    },
    increase: function() {
        if (this.inc < this.max) {
            this.removeClass(this.inc);
            this.inc++;
            this.setClass();
        }
    },
    decrease: function() {
        if (this.inc > 1) {
            this.removeClass();
            this.inc--;
            this.setClass();
        }
    }
});
document.observe('dom:loaded', function() {
    var changePageClass = new FluctuatePageClass({ start: '', max: 4 });
    $$('.textSize .increase').each(function(el) { el.observe('click', function() { changePageClass.increase(); }); });
    $$('.textSize .decrease').each(function(el) { el.observe('click', function() { changePageClass.decrease(); }); });
});

