(function($) {
  
  var textZoom = {

    DEFAULT_INDEX: 1,
    LEVELS: [65, 75, 85, 100],
    LEVELS_DESC: ["small", "medium-small", "medium-large", "large"],
    currentIndex: null,
    previousIndex: null,

    init: function() {
      this.currentIndex = parseInt(biooncIAC.helpers.getCookie('zoom'), 10) || this.DEFAULT_INDEX;
      this.update(true);
    },
    
    changeZoom: function(action) {
      switch (action) {
        case "minus":
          this.currentIndex = Math.max(this.currentIndex - 1, 0);
          break;
        case "plus":
          this.currentIndex = Math.min(this.currentIndex + 1, this.LEVELS.length - 1);
          break;
        case "reset":
          this.currentIndex = this.DEFAULT_INDEX;
          break;
      }
      if (typeof action !== "undefined") {
        this.update();
      }
    },

    update: function(init) {
      if (this.currentIndex !== this.previousIndex || init) {
        document.body.style.fontSize = this.LEVELS[this.currentIndex] + '%';
        biooncIAC.helpers.setCookie('zoom', this.currentIndex, 365, '/');
        if (!init) biooncIAC.analytics.callAdapters('changeFontSize', this.LEVELS_DESC[this.currentIndex]);
      }
      this.previousIndex = this.currentIndex;
    }
  };
  
  $(document).ready(function() {
    textZoom.init();
    $(".text-zoom a").click(function(e) {
      e.preventDefault();
      e.stopPropagation();
      textZoom.changeZoom($(this).attr('class'));
    });
  });
  
})(jQuery);

