StvFontSize = Class.create();



StvFontSize.prototype = {



  per: 13,

  

  per_priset: {

    small: 11,

    middle: 13,

    big: 16

  },

  

    // From Cookie

  initialize: function(cookieName){

      this.cookieName = cookieName;

      var fontsize = FontSizeCmanager.getCookie(cookieName);

      if (!fontsize){

          // no cookie

          fontsize = "middle";

      }

      this.change(fontsize);

      

      // add event listenrs

      var self = this;

      $A($('textSize').getElementsByTagName('img')).each(function(img){

          Event.observe(img, "click", function(e){

              if (Event.element(e).tagName != "IMG") return ;

              if (Event.element(e).src.match(/\/font_(\w+)(_on)?\.gif$/)){

                  self.change(RegExp.$1);

              }

          });

      });

  },

  

  // change fontsize

  change: function(fontsize){

      

      if (!this.per_priset[fontsize]) return ;

      

      this.per = this.per_priset[fontsize];

      

      this.changeImg(fontsize);

      

      FontSizeCmanager.setCookie(this.cookieName, String(fontsize));

      if (this.per != 1){

          document.body.style.fontSize = this.per + 'px';

      }

      else {

          document.body.style.fontSize = "";

      }

  },

  

  changeImg: function(fontsize)

  {

      var self = this;

      $A($('textSize').getElementsByTagName('img')).each(function(img){

          if (img.src.match(/\/font_(\w+)(_on)?\.gif$/)){

              if (RegExp.$1 == fontsize){

                  self.toOnGif(img);

              } else {

                  self.delOnGif(img);

              }

          }

      });

  },

  

    // add _on to.gif

  toOnGif: function(img)

  {

      if (img.src.match(/^(.+)\.gif$/)){

          img.src = RegExp.$1+'_on.gif';

      }

      img.style.cursor = "auto";

  },

    // remove _on from.gif

  delOnGif: function(img)

  {

      if (img.src.match(/^(.+)_on\.gif$/)){

          img.src = RegExp.$1+'.gif';

      }

      img.style.cursor = "pointer";

  }

}





Event.observe(window, "load", function(){

    FontSizeCmanager = new CookieManager();

    fontsize = new StvFontSize("fontsize");

});


