// FontChanger
// Copyright (c) 2007 Hirotaka Ogawa
// REQUIRES: prototype.js, cookiemanager.js

var urlpath = this.document.location.pathname;

FontChanger = Class.create();
FontChanger.prototype = {
  id: null,
  cookieManager: null,
  cookieName: 'body.style.fontSize',
  initialize: function(id) {
    this.id = id || 'fontChanger';
    this.cookieManager = new CookieManager();
    this.cookieManager.cookieShelfLife = 90;
    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;
    document.writeln([
'<a href="javascript: void(0);" id="' + id + '-small" title="文字を小さくする（84％）"><img src="http://sky-fish.net/shopping/magic-merry/includes/templates//merry/images/nav_fc_small.gif" alt="小さい文字サイズ" width="17" height="20" border="0" name="img_small" /></a><a href="javascript: void(0);" id="' + id + '-medium" title="文字を標準に戻す（100％）"><img src="http://sky-fish.net/shopping/magic-merry/includes/templates//merry/images/nav_fc_medium.gif" alt="中文字サイズ" width="17" height="20" border="0" name="img_medium" /></a><a href="javascript: void(0);" id="' + id + '-large" title="文字を大きくする（120％）"><img src="http://sky-fish.net/shopping/magic-merry/includes/templates//merry/images/nav_fc_large.gif" alt="大きい文字サイズ" width="18" height="20" border="0" name="img_large" /></a>',
    ].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) { chimg3(); this.change('0.8em' ); },
  onClickMedium: function(e) { chimg2(); this.change('1.0em'); },
  onClickLarge:  function(e) { chimg1(); this.change('1.4em'); }
};
// Bootstrap
FontChanger.start = function(id) {
	var fontChanger = new FontChanger(id);
	fontChanger.setCookieShelfLife(50);
	fontChanger.show();
};

function chimg1() {
	document.img_small.src = "http://sky-fish.net/shopping/magic-merry/includes/templates//merry/images/nav_fc_small.gif";
	document.img_medium.src = "http://sky-fish.net/shopping/magic-merry/includes/templates//merry/images/nav_fc_medium.gif";
	document.img_large.src = "http://sky-fish.net/shopping/magic-merry/includes/templates//merry/images/nav_fc_large_on.gif";
}

function chimg2() {
	document.img_small.src = "http://sky-fish.net/shopping/magic-merry/includes/templates//merry/images/nav_fc_small.gif";
	document.img_medium.src = "http://sky-fish.net/shopping/magic-merry/includes/templates//merry/images/nav_fc_medium_on.gif";
	document.img_large.src = "http://sky-fish.net/shopping/magic-merry/includes/templates//merry/images/nav_fc_large.gif";
}

function chimg3() {
	document.img_small.src = "http://sky-fish.net/shopping/magic-merry/includes/templates//merry/images/nav_fc_small_on.gif";
	document.img_medium.src = "http://sky-fish.net/shopping/magic-merry/includes/templates//merry/images/nav_fc_medium.gif";
	document.img_large.src = "http://sky-fish.net/shopping/magic-merry/includes/templates//merry/images/nav_fc_large.gif";
}
