var TextZoom = Class.create({

    DEFAULT_INDEX: 1,
    LEVELS: [55, 62.5, 70, 75],

    _context: null,

    initialize: function(context) {
      this._context = context;
      var zoom = null;
      try {
        zoom = this._context.getCookie().zoom;
      } catch(e) { }
      this.index = (zoom) ? Number(zoom) : this.DEFAULT_INDEX;
      this.update();
      this.setupLinks();
    },

    setupLinks: function() {
      var tool = $$("li.zoom").pop();
      var links = tool.getElementsByTagName("a");
      for(var i=0;i<links.length;i++) {
        var link = $(links[i]);
        if(link.hasClassName("btn-minus")) {
          link.observe("click", this.zoomOut.bind(this));
        } else if(link.hasClassName("btn-aaa")) {
          link.observe("click", this.zoomDefault.bind(this));
        } else if(link.hasClassName("btn-plus")) {
          link.observe("click", this.zoomIn.bind(this));
        }
      }

    },

    /** these functions are to be called in the textZoom scope so 'this' is textZoom */
    zoomIn: function(event){
      event.preventDefault();
      this.index = Math.min(this.index + 1, this.LEVELS.length - 1);
      this.update(); 
    },
  
    zoomOut: function(event){
      event.preventDefault();
      this.index = Math.max(this.index - 1, 0);
      this.update();
    },
    
    zoomDefault: function(event){
      event.preventDefault();
      this.index = this.DEFAULT_INDEX;
      this.update();
    },
    
    update: function(){
      document.body.style.fontSize = this.LEVELS[this.index] + '%';
      this._context.setCookie({zoom: this.index});
    },
    
    getIndex: function(){
      return this.index;
    }

  });
