// 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 (document.body.style.fontSize == '14px'){
		
    document.writeln([

'<ul id="Changerbk" class="Changerbk-l">',
'<li><a href="javascript:void(0);" onFocus="this.blur()" id="' + id + '-large">大</a></li>',
'<li><a href="javascript:void(0);" onFocus="this.blur()" id="' + id + '-medium">中</a></li>',
'<li><a href="javascript:void(0);" onFocus="this.blur()" id="' + id + '-small">小</a></li>',
'</ul>'
    ].join("\n"));
		
	}

	else if (document.body.style.fontSize == '10px'){

    document.writeln([
'<ul id="Changerbk" class="Changerbk-s">',
'<li><a href="#" onFocus="this.blur()" id="' + id + '-large">大</a></li>',
'<li><a href="#" onFocus="this.blur()" id="' + id + '-medium">中</a></li>',
'<li><a href="#" onFocus="this.blur()" id="' + id + '-small">小</a></li>',
'</ul>'
    ].join("\n"));
	
	}

	else{

    document.writeln([
'<ul id="Changerbk" class="Changerbk-m">',
'<li><a href="#" onFocus="this.blur()" id="' + id + '-large">大</a></li>',
'<li><a href="#" onFocus="this.blur()" id="' + id + '-medium">中</a></li>',
'<li><a href="#" onFocus="this.blur()" id="' + id + '-small">小</a></li>',
'</ul>'
    ].join("\n"));
	
	}
	
	
	
    Event.observe($(id + '-large' ), 'click', this.onClickLarge.bind(this));
    Event.observe($(id + '-medium'), 'click', this.onClickMedium.bind(this));
	Event.observe($(id + '-small' ), 'click', this.onClickSmall.bind(this));
  },
  onClickLarge:  function(e) { this.change('14px');
  document.getElementById("Changerbk").className = "Changerbk-l"; },
  onClickMedium: function(e) { this.change('12px');
  document.getElementById("Changerbk").className = "Changerbk-m"; },
  onClickSmall:  function(e) { this.change('10px' );
  document.getElementById("Changerbk").className = "Changerbk-s"; }

};
// Bootstrap
FontChanger.start = function(id) {
  var fontChanger = new FontChanger(id);
  fontChanger.show();
};
