// FontChanger
// Copyright (c) 2007 Hirotaka Ogawa
// REQUIRES: prototype.js, cookiemanager.js
var fontChanger;
FontChanger = Class.create();
FontChanger.prototype = {
  id: null,
  cookieManager: null,
  cookieName: 'body.style.fontSize',
  fSize: '100%',
  sizeList: null,
  initialize: function(id) {
    this.sizeList = new Array();
    this.sizeList['93.75%'] = 'small';
    this.sizeList['100%'] = 'normal';
    this.sizeList['112.5%'] = 'large';
    
	this.id = id || 'fontChanger';
    this.cookieManager = new CookieManager();
    var fontSize = this.cookieManager.getCookie(this.cookieName);
    if (fontSize){
       /* document.body.style.fontSize = fontSize;*/
        this.fSize = fontSize;
    }
  },
  setCookieShelfLife: function(days) {
    this.cookieManager.cookieShelfLife = days;
  },
  change: function(fontSize) {
    org_fontSize = document.getElementById("maincontents").style.fontSize;
    document.getElementById("maincontents").style.fontSize = fontSize;
    this.cookieManager.setCookie(this.cookieName, fontSize);
    this.buildChangeButton(fontSize, org_fontSize);
  },
  buildChangeButton: function(fontSize, org_fontSize) {
    altString=new Array();
    altString['93.75%']='小さく';
    altString['100%']  ='標準サイズに';
    altString['112.5%']='大きく';
    var id = this.id;
    if (org_fontSize != null) {
      org_sizeText = this.sizeList[org_fontSize];
      document.getElementById(id+'-'+org_sizeText).innerHTML = '<a href="javascript:void(0)"><img id="imgID3" src="/images/common/breadcrumbs/breadcrumbs_font_'+org_sizeText+'.png" width="22" height="22" alt="'+altString[org_fontSize]+'" title="'+altString[org_fontSize]+'" /></a>';
    }
    sizeText = this.sizeList[fontSize];
    document.getElementById(id+'-'+sizeText).innerHTML = '<img id="imgID3" src="/images/common/breadcrumbs/breadcrumbs_font_'+sizeText+'_a.png" width="22" height="22" alt="'+altString[fontSize]+'" title="'+altString[fontSize]+'" />';
  },
  get: function(){
    document.getElementById("maincontents").style.fontSize = this.fSize;
    this.buildChangeButton(this.fSize, null);
  },
  reset: function() {
    document.getElementById("maincontents").style.fontSize = '';
    this.cookieManager.clearCookie(this.cookieName);
  },
  show: function() {
    var id = this.id;
    document.writeln([
'<ul id="' + id + '">',
'<li><a href="/external/help.html"><img src="/images/common/breadcrumbs/breadcrumbs_help.png" width="60" height="22" alt="ヘルプ" title="ヘルプ" /></a></li>\
<li><img src="/images/common/breadcrumbs/breadcrumbs_font_size.png" width="80" height="22" alt="文字サイズの変更" title="文字サイズの変更" />\
<ul><li id="' + id + '-small"><a href="javascript:void(0)"><img id="imgID1" src="/images/common/breadcrumbs/breadcrumbs_font_small.png" width="22" height="22" alt="文字を小さく" title="文字を小さく" /></a></li>\
<li id="' + id + '-normal"><a href="javascript:void(0)"><img id="imgID2" src="/images/common/breadcrumbs/breadcrumbs_font_normal.png" width="22" height="22" alt="文字を標準サイズに" title="文字を標準サイズに" /></a></li>\
<li id="' + id + '-large"><a href="javascript:void(0)"><img id="imgID3" src="/images/common/breadcrumbs/breadcrumbs_font_large.png" width="22" height="22" alt="文字を大きく" title="文字を大きく" /></a></li>\
</ul></li></ul>',

    ].join("\n"));
    Event.observe($(id + '-small' ), 'click', this.onClickSmall.bind(this));
    Event.observe($(id + '-normal'), 'click', this.onClickMedium.bind(this));
    Event.observe($(id + '-large' ), 'click', this.onClickLarge.bind(this));
  },
  onClickSmall:  function(e) { this.change('93.75%'); },
  onClickMedium: function(e) { this.change('100%'); },
  onClickLarge:  function(e) { this.change('112.5%'); }
};
// Bootstrap
FontChanger.start = function(id) {
  var fontChanger = new FontChanger(id);
  fontChanger.show();
};
FontChanger.get = function(id) {
  var fontChanger = new FontChanger(id);
  fontChanger.get();
};
