﻿// FontChanger
// Copyright (c) 2007 Hirotaka Ogawa
// REQUIRES: prototype.js, cookiemanager.js
FontChanger = Class.create();
FontChanger.prototype = {
  id: null,
  cookieManager: null,
  cookieName: 'body.style.fontSize',
  initialize: function(id) {
    this.id = id || 'fontChanger';
    this.cookieManager = new CookieManager();
    var fontSize = this.cookieManager.getCookie(this.cookieName);
    if (fontSize) document.body.style.fontSize = fontSize;
  },
  setCookieShelfLife: function(days) {
    this.cookieManager.cookieShelfLife = days;
  },
  change: function(fontSize) {
    document.body.style.fontSize = fontSize;
    this.cookieManager.setCookie(this.cookieName, fontSize);
  },
  reset: function() {
    document.body.style.fontSize = '';
    this.cookieManager.clearCookie(this.cookieName);
  },
  show: function() {

    var id = this.id;

// 会員ページ
if(id=="kaiin"){
	normale_picturename ="../image/normalsize_k.gif";
	big_picturename ="../image/bigsize_k.gif";
}else if(id=="kaiintop"){
	normale_picturename ="../image/normalsize_k.gif";
	big_picturename ="../image/bigsize_k.gif";
}else if(id=="ippantop"){
	normale_picturename ="image/normalsize.gif";
	big_picturename ="image/bigsize.gif";
}else{
	normale_picturename ="../../image/normalsize.gif";
	big_picturename ="../../image/bigsize.gif";
}

document.writeln([
'<p id="' + id + '">',
'<span class="fontcaption"><font color="white">文字サイズ </font></span>',
'<a href="javascript: void(0);" id="' + id + '-small" title="文字を標準にする"><img src="' + normale_picturename + '" width="24" height="24" alt="標準" /></a>',
'<a href="javascript: void(0);" id="' + id + '-medium" title="文字を大きくする"><img src="' + big_picturename + '" width="24" height="24" alt="大" /></a>',
'<a href="javascript: void(0);" id="' + id + '-large" title=""></a>',
'</p>'
    ].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('77%' ); },
  onClickMedium: function(e) { this.change('95%'); },
  onClickLarge:  function(e) { this.change('120%'); }
};
// Bootstrap
FontChanger.start = function(id) {
  var fontChanger = new FontChanger(id);

if(id != "nobutton"){
	fontChanger.show();
 }

};
