// FontChanger
// Copyright (c) 2007 Hirotaka Ogawa
// REQUIRES: prototype.js, cookiemanager.js
FontChanger = Class.create();
FontChanger.prototype = {
  id: null,
  cookieManager: null,
  cookieName: 'body.style.fontSize',

// ファイルパス指定===============================================================================================
  filepath: './',
//=================================================================================================================

  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;
    if (fontSize) document.getElementById('font').href= this.filepath + '/common/css/' + fontSize + '.css';
  },
  setCookieShelfLife: function(days) {
    this.cookieManager.cookieShelfLife = days;
  },
  change: function(fontSize) {
    //document.body.style.fontSize = fontSize;
    document.getElementById('font').href = this.filepath + '/common/css/' + fontSize + '.css';

    this.cookieManager.setCookie(this.cookieName, fontSize);
	
	var id = this.id;
	//alert(fontSize);
	// 選択されている内容でメニューを切替
	if(fontSize=="small"){
		document.getElementById(id + '-small').innerHTML = '<img src="' + this.filepath + '/common/img/button_small_on.gif" width="19" height="19" alt="">';
		document.getElementById(id + '-medium').innerHTML = '<img src="' + this.filepath + '/common/img/button_middle_off.gif" width="19" height="19" alt="">';
		document.getElementById(id + '-large').innerHTML = '<img src="' + this.filepath + '/common/img/button_big_off.gif" width="19" height="19" alt="">';
	}else if(fontSize=="medium"){
		document.getElementById(id + '-small').innerHTML = '<img src="' + this.filepath + '/common/img/button_small_off.gif" width="19" height="19" alt="">';
		document.getElementById(id + '-medium').innerHTML = '<img src="' + this.filepath + '/common/img/button_middle_on.gif" width="19" height="19" alt="">';
		document.getElementById(id + '-large').innerHTML = '<img src="' + this.filepath + '/common/img/button_big_off.gif" width="19" height="19" alt="">';
	}else if(fontSize=="large"){
		document.getElementById(id + '-small').innerHTML = '<img src="' + this.filepath + '/common/img/button_small_off.gif" width="19" height="19" alt="">';
		document.getElementById(id + '-medium').innerHTML = '<img src="' + this.filepath + '/common/img/button_middle_off.gif" width="19" height="19" alt="">';
		document.getElementById(id + '-large').innerHTML = '<img src="' + this.filepath + '/common/img/button_big_on.gif" width="19" height="19" alt="">';
	}
  },
  reset: function() {
    document.body.style.fontSize = '';
    this.cookieManager.clearCookie(this.cookieName);
  },
  show: function() {
    var id = this.id;
	
    document.writeln(
		'<div id="' + id + '">',
		'<img src="' + this.filepath + '/common/img/img_textsize.gif" width="67" height="19" alt="">',
		'<span style="cursor: pointer; margin-left: 4px;" id="' + id + '-large" ><img src="' + this.filepath + '/common/img/button_big_off.gif" width="19" height="19" alt=""></span></span>',
		'<span style="cursor: pointer; margin-left: 4px;" id="' + id + '-medium"><img src="' + this.filepath + '/common/img/button_middle_on.gif" width="19" height="19" alt=""></span>',
		'<span style="cursor: pointer; margin-left: 4px;" id="' + id + '-small" ><img src="' + this.filepath + '/common/img/button_small_off.gif" width="19" height="19" alt=""></span>',
		'</div>');
	
	// 選択されている内容でメニューを切替
	if(this.cookieManager.getCookie(this.cookieName)=="small"){
		document.getElementById(id + '-small').innerHTML = '<img src="' + this.filepath + '/common/img/button_small_on.gif" width="19" height="19" alt="">';
		document.getElementById(id + '-medium').innerHTML = '<img src="' + this.filepath + '/common/img/button_middle_off.gif" width="19" height="19" alt="">';
		document.getElementById(id + '-large').innerHTML = '<img src="' + this.filepath + '/common/img/button_big_off.gif" width="19" height="19" alt="">';
	}else if(this.cookieManager.getCookie(this.cookieName)=="medium"){
		document.getElementById(id + '-small').innerHTML = '<img src="' + this.filepath + '/common/img/button_small_off.gif" width="19" height="19" alt="">';
		document.getElementById(id + '-medium').innerHTML = '<img src="' + this.filepath + '/common/img/button_middle_on.gif" width="19" height="19" alt="">';
		document.getElementById(id + '-large').innerHTML = '<img src="' + this.filepath + '/common/img/button_big_off.gif" width="19" height="19" alt="">';
	}else if(this.cookieManager.getCookie(this.cookieName)=="large"){
		document.getElementById(id + '-small').innerHTML = '<img src="' + this.filepath + '/common/img/button_small_off.gif" width="19" height="19" alt="">';
		document.getElementById(id + '-medium').innerHTML = '<img src="' + this.filepath + '/common/img/button_middle_off.gif" width="19" height="19" alt="">';
		document.getElementById(id + '-large').innerHTML = '<img src="' + this.filepath + '/common/img/button_big_on.gif" width="19" height="19" alt="">';
	}
	
    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('small' ); },
  onClickMedium: function(e) { this.change('medium'); },
  onClickLarge:  function(e) { this.change('large'); }
};
// Bootstrap
FontChanger.start = function(id) {
  var fontChanger = new FontChanger(id);
  fontChanger.show();
};
