// JavaScript Document

// 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;
    document.writeln([
'<div id="' + id + '">',
'<p id="large"></p> ',
'<p id="medium"></p> ',
'<p id="small"></p> ',
'</div>'
    ].join("\n"));
	var fontLarge  = $('large');
	var fontMedium = $('medium');
	var fontSmall  = $('small');
	
	Event.observe(fontLarge , 'click', this.onClickLarge.bind(this));
	Event.observe(fontMedium, 'click', this.onClickMedium.bind(this));
	Event.observe(fontSmall , 'click', this.onClickSmall.bind(this));
	
	Event.observe(fontLarge, 'mouseover', function(e) { fontLarge.style.backgroundImage ='url(http://www.fukushi-saitama.or.jp/site/image/font_large_on.gif)';  });
	Event.observe(fontMedium,'mouseover', function(e) { fontMedium.style.backgroundImage='url(http://www.fukushi-saitama.or.jp/site/image/font_medium_on.gif)'; });
	Event.observe(fontSmall, 'mouseover', function(e) { fontSmall.style.backgroundImage ='url(http://www.fukushi-saitama.or.jp/site/image/font_small_on.gif)';  });	
	
	Event.observe(fontLarge, 'mouseout', function(e) { fontLarge.style.backgroundImage ='url(http://www.fukushi-saitama.or.jp/site/image/font_large.gif)';  });
	Event.observe(fontMedium,'mouseout', function(e) { fontMedium.style.backgroundImage='url(http://www.fukushi-saitama.or.jp/site/image/font_medium.gif)'; });
	Event.observe(fontSmall, 'mouseout', function(e) { fontSmall.style.backgroundImage ='url(http://www.fukushi-saitama.or.jp/site/image/font_small.gif)';  });		
  },
  onClickLarge  : function(e) { this.change('140%');  },
  onClickMedium : function(e) { this.change('120%');  },
  onClickSmall  : function(e) { this.change('100%' ); }
};
// Bootstrap
FontChanger.start = function(id) {
  var fontChanger = new FontChanger(id);
  fontChanger.show();
};