// FontChanger
// Copyright (c) 2007 Hirotaka Ogawa
// REQUIRES: prototype.js, cookiemanager.js
FontChanger = Class.create();
FontChanger.prototype = {
  id: null,
  cookieManager: null,
  cookieName: 'pmibody.style.fontSize',
  initialize: function(id) {
    this.id = id || 'fontChanger';
    this.cookieManager = new CookieManager();

  },
  setCookieShelfLife: function(days) {
    this.cookieManager.cookieShelfLife = days;
  },
  change: function(fontSize) {

    if(fontSize == ''){
      fontSize = this.cookieManager.getCookie(this.cookieName);
      if(fontSize == '' || fontSize == 'null'){
        fontSize = '80%';
      }
    }

    document.body.style.fontSize = fontSize;
    this.cookieManager.setCookie(this.cookieName, fontSize);

    var imgSS = "/common/images/fsize_small.gif";
    var imgMM = "/common/images/fsize_middle.gif";
    var imgLL = "/common/images/fsize_big.gif";
    if(fontSize == '100%'){
        imgLL = "/common/images/fsize_big_on.gif";
    }else if(fontSize == '65%'){
        imgSS = "/common/images/fsize_small_on.gif";
    }else{ // if(fontSize == "80%"){
        imgMM = "/common/images/fsize_middle_on.gif";
    }
    var id = this.id;
    $(id + '-small' ).src = imgSS;
    $(id + '-medium' ).src = imgMM;
    $(id + '-large' ).src = imgLL;
  },
  reset: function() {
    document.body.style.fontSize = '';
    this.cookieManager.clearCookie(this.cookieName);
  },
  show: function() {

    var id = this.id;
    document.writeln([
'<div id="' + id + '">',
'<img src="/common/images/btn_fontsize.gif" alt="文字サイズ変更" hspace="9"><img id="' + id + '-small" src="/common/imagesg/fsize_small.gif" alt="小" style="cursor:pointer"><img id="' + id + '-medium" src="/common/images/fsize_middle_over.gif" alt="中" style="cursor:pointer" hspace="6"><img id="' + id + '-large" src="/common/images/fsize_big.gif" alt="大" style="cursor:pointer" class="mg10r">',
'</div>'
    ].join("\n"));
    Event.observe($(id + '-small' ), 'click', this.onClickSmall.bind(this));
    Event.observe($(id + '-medium'), 'click', this.onClickMedium.bind(this));
    Event.observe($(id + '-large' ), 'click', this.onClickLarge.bind(this));
  },
  onClickSmall:  function(e) { this.change('65%' ); },
  onClickMedium: function(e) { this.change('80%'); },
  onClickLarge:  function(e) { this.change('100%'); }
};
// Bootstrap
FontChanger.start = function(id) {
  var fontChanger = new FontChanger(id);
  fontChanger.setCookieShelfLife(90);
  fontChanger.show();

  fontChanger.change('');
};


