// 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);
	document.getElementById(this.id+'-small' ).firstChild.src = '../img/font_size01.gif';
	document.getElementById(this.id+'-medium').firstChild.src = '../img/font_size02.gif';
	document.getElementById(this.id+'-large' ).firstChild.src = '../img/font_size03.gif';
	if(      fontSize ==  '80%' )	{document.getElementById(this.id+'-small' ).firstChild.src = '../img/font_size01_now.gif';}
	else if( fontSize == '100%' )	{document.getElementById(this.id+'-medium').firstChild.src = '../img/font_size02_now.gif';}
	else if( fontSize == '120%' )	{document.getElementById(this.id+'-large' ).firstChild.src = '../img/font_size03_now.gif';}
  },
  reset: function() {
    document.body.style.fontSize = '';
    this.cookieManager.clearCookie(this.cookieName);
  },
  show: function() {
    var id = this.id;
	if( document.body.style.fontSize == '80%' )
		{
    document.writeln([
'<div id="' + id + '">',
'<span style="font-size:12px;"><b>文字の大きさ&nbsp;&nbsp;:</b></span>&nbsp;&nbsp; ',
'<span style="cursor: pointer; font-size: 80% ;" id="' + id + '-small" ><img src="../img/font_size01_now.gif"></span>',
'<span style="cursor: pointer; font-size: 100%;" id="' + id + '-medium"><img src="../img/font_size02.gif"></span>',
'<span style="cursor: pointer; font-size: 120%;" id="' + id + '-large" ><img src="../img/font_size03.gif"></span>',
'</div>'
    ].join("\n"));
		}
	else if( document.body.style.fontSize == '100%' )
		{
    document.writeln([
'<div id="' + id + '">',
'<span style="font-size:12px;"><b>文字の大きさ&nbsp;&nbsp;:</b></span>&nbsp;&nbsp; ',
'<span style="cursor: pointer; font-size: 80% ;" id="' + id + '-small" ><img src="../img/font_size01.gif"></span>',
'<span style="cursor: pointer; font-size: 100%;" id="' + id + '-medium"><img src="../img/font_size02_now.gif"></span>',
'<span style="cursor: pointer; font-size: 120%;" id="' + id + '-large" ><img src="../img/font_size03.gif"></span>',
'</div>'
    ].join("\n"));
		}
	else if( document.body.style.fontSize == '120%' )
		{
    document.writeln([
'<div id="' + id + '">',
'<span style="font-size:12px;"><b>文字の大きさ&nbsp;&nbsp;:</b></span>&nbsp;&nbsp; ',
'<span style="cursor: pointer; font-size: 80% ;" id="' + id + '-small" ><img src="../img/font_size01.gif"></span>',
'<span style="cursor: pointer; font-size: 100%;" id="' + id + '-medium"><img src="../img/font_size02.gif"></span>',
'<span style="cursor: pointer; font-size: 120%;" id="' + id + '-large" ><img src="../img/font_size03_now.gif"></span>',
'</div>'
    ].join("\n"));
		}
	else
		{
    document.writeln([
'<div id="' + id + '">',
'<span style="font-size:12px;"><b>文字の大きさ&nbsp;&nbsp;:</b></span>&nbsp;&nbsp; ',
'<span style="cursor: pointer; font-size: 80% ;" id="' + id + '-small" ><img src="../img/font_size01_now.gif"></span>',
'<span style="cursor: pointer; font-size: 100%;" id="' + id + '-medium"><img src="../img/font_size02.gif"></span>',
'<span style="cursor: pointer; font-size: 120%;" id="' + id + '-large" ><img src="../img/font_size03.gif"></span>',
'</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('80%' ); },
  onClickMedium: function(e) { this.change('100%'); },
  onClickLarge:  function(e) { this.change('120%'); }
};
// Bootstrap
FontChanger.start = function(id) {
  var fontChanger = new FontChanger(id);
  fontChanger.show();
};

