FontChanger = Class.create();
FontChanger.prototype = {
	fontSize_s: '80%',
	fontSize_m: '100%',
	fontSize_l: '120%',
	button_def_s: './img/button_def_s.png',
	button_def_m: './img/button_def_m.png',
	button_def_l: './img/button_def_l.png',
	button_sel_s: './img/button_sel_s.png',
	button_sel_m: './img/button_sel_m.png',
	button_sel_l: './img/button_sel_l.png',
	id: null,
	cookieManager: null,
	cookieName: 'body.style.fontSize',
	setCookieShelfLife: function(days) {
		this.cookieManager.cookieShelfLife = days;
	},
	buttonChange: function(imgId) {
		if(imgId != 'button_s') {
			document.getElementById('button_s').src = this.button_def_s;
		} else {
			document.getElementById('button_s').src = this.button_sel_s;
			document.body.style.fontSize = this.fontSize_s;
			parent.document.body.style.fontSize = this.fontSize_s;
			parent.footer.document.body.style.fontSize = this.fontSize_s;
		}
		if(imgId != 'button_m') {
			document.getElementById('button_m').src = this.button_def_m;
		} else {
			document.getElementById('button_m').src = this.button_sel_m;
			document.body.style.fontSize = this.fontSize_m;
			parent.document.body.style.fontSize = this.fontSize_m;
			parent.footer.document.body.style.fontSize = this.fontSize_m;
		}
		if(imgId != 'button_l') {
			document.getElementById('button_l').src = this.button_def_l;
		} else {
			document.getElementById('button_l').src = this.button_sel_l;
			document.body.style.fontSize = this.fontSize_l;
			parent.document.body.style.fontSize = this.fontSize_l;
			parent.footer.document.body.style.fontSize = this.fontSize_l;
		}
	},
	change: function(imgId) {
		this.buttonChange(imgId);
		this.cookieManager.setCookie(this.cookieName,imgId);
	},
	initialize: function(id) {
		this.id = id || 'fontChanger';
		this.cookieManager = new CookieManager();
		var imgId = this.cookieManager.getCookie(this.cookieName);
		if (imgId) { function(e) { this.change(imgId); } }
	},
	reset: function() {
		document.body.style.fontSize = '';
		this.cookieManager.clearCookie(this.cookieName);
	},
	show: function() {
		var id = this.id;
		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('button_s'); },
	onClickMedium: function(e) { this.change('button_m'); },
	onClickLarge:  function(e) { this.change('button_l'); }
};
// Bootstrap
FontChanger.initialize = function(id) {
	var fontChanger = new FontChanger(id);
	fontChanger.initialize(id);
};
FontChanger.start = function(id) {
	var fontChanger = new FontChanger(id);
	fontChanger.setCookieShelfLife(30);
	fontChanger.show();
};

