var FontSizer = Class.create({
	node:null,
	curFontSize:null,
	initialize: function(id) {
		this.node = $(id);

		if (this.node) {
			this.bindEvents();

			if (Cookie.get('fontSize')) {
				this.node.setStyle({fontSize:Cookie.get('fontSize')});
				this.curFontSize = Cookie.get('fontSize');
			} else
				this.curFontSize = this.node.getStyle('fontSize');
		}
	},

	bindEvents: function()
	{
		var arr = $$('.incFont');

		for (var i = 0; i<arr.length; i++) {
			arr[i].observe('click', this.changeFont.bindAsEventListener(this,'inc'));
		}

		arr = $$('.decFont');

		for (var i = 0; i<arr.length; i++) {
			arr[i].observe('click', this.changeFont.bindAsEventListener(this,'dec'));
		}
	},

	changeFont: function()
	{
		var newSize = null;
		if (this.curFontSize.indexOf('px') != '-1') {
			newSize = parseInt(this.curFontSize) + (arguments[1] == 'inc' ? 2 : -2);
			if (newSize > 4 && newSize < 26) this.curFontSize = newSize + 'px';
		} else if (this.curFontSize.indexOf('%') != '-1') {
			newSize = parseInt(this.curFontSize) + (arguments[1] == 'inc' ? 10 : -10);
			if (newSize > 50 && newSize < 300) this.curFontSize = newSize + '%';
		}

		this.node.setStyle({fontSize:this.curFontSize});
		Cookie.set('fontSize', this.curFontSize, 180, '/');
	}

});
