﻿var FontSize = new Class({
  Implements: [Options],

  options: {
    minSize: 0,
    maxSize: 4
  },

  curSize: 1,

  curClass: '',

  initialize: function(options) {
    this.setOptions(options);

    if (Cookie.read('fontsize') != null) {
      this.curSize = Cookie.read('fontsize');
    }

    this.apply();
  },

  decrease: function() {
    if (this.curSize > this.options.minSize) {
      this.curSize--;
      this.save();
    }
  },

  increase: function() {
    if (this.curSize < this.options.maxSize) {
      this.curSize++;
      this.save();
    }
  },

  apply: function() {
    if (this.curClass != '') {
      $(document.body).removeClass(this.curClass);
    }
    this.curClass = 'fontsize' + this.curSize;
    $(document.body).addClass(this.curClass);
  },

  save: function() {
    this.apply();
    Cookie.write('fontsize', this.curSize);
  }
});