var CFontSizer = Class.create();
CFontSizer.prototype = {
	initialize: function(){
		size = this.getCookie('fontSizer') * 1;
		if (size) {
			this.setFontSize(size);
		}
		
		Event.observe('increaseFontSize', 'click', function(obj){
			return function() { obj.increaseFontSize() }
		}(this) );
		Event.observe('decreaseFontSize', 'click', function(obj){
			return function() { obj.decreaseFontSize() }
		}(this));
	},//---------------------------------------------------------------------
	pickContent: function(){
		//this.p = $$('#content p, #content li, #content td, #content h1, #content h2, #content h3, #content a');
		this.p = $$('#container p, #container li, #container td, #container h1, #container h2, #container h3, #container a');
	},//---------------------------------------------------------------------
	setFontSize: function(size){
		if (this.p === null) 
			this.pickContent();
		for (i = 0; i < this.p.length; i++) 
			this.p[i].style.fontSize = size + "pt";
		this.saveState(size)
	},//---------------------------------------------------------------------
	maxFontSize: function(){
		this.setFontSize(this.max);
	},//---------------------------------------------------------------------
	minFontSize: function(){
		this.setFontSize(this.min);
	},//---------------------------------------------------------------------
	increaseFontSize: function(){
		if (this.p === null) {
			this.pickContent();
		}
		for (i = 0; i < this.p.length; i++) {
			var s = this.defaultSize;
			if (this.p[i].style.fontSize) {
				s = parseInt(this.p[i].style.fontSize.replace("pt", ""), 10);
			}
			else {
				s = this.defaultSize;
			}
			if (s != this.max) {
				s += 1;
			}
			this.p[i].style.fontSize = s + "pt";
		}
		this.saveState(s);
	},//---------------------------------------------------------------------
	decreaseFontSize: function(){
		if (this.p === null) {
			this.pickContent();
		}
		for (i = 0; i < this.p.length; i++) {
			var s = this.defaultSize;
			if (this.p[i].style.fontSize) {
				s = parseInt(this.p[i].style.fontSize.replace("pt", ""), 10);
			}
			else 
				s = this.defaultSize;
			if (s != this.min) 
				s -= 1;
			this.p[i].style.fontSize = s + "pt";
		}
		this.saveState(s);
	},//---------------------------------------------------------------------
	saveState: function(curSize){
		this.size = curSize;
		var date = new Date();
		date.setTime(date.getTime() + (7 * 24 * 60 * 60 * 1000));
		var expires = "; expires=" + date.toGMTString();
		if (curSize == this.defaultSize) {
			document.cookie = "fontSizer=0" + expires + "; path=/";
		}
		else {
			document.cookie = "fontSizer" + "=" + curSize + expires + "; path=/";
		}
	},//---------------------------------------------------------------------
	getCookie: function(cookieName){
		if (document.cookie.length > 0) {
			var startOffset = document.cookie.indexOf(cookieName + "=");
			if (startOffset != -1) {
				startOffset = startOffset + cookieName.length + 1;
				var endOffset = document.cookie.indexOf(";", startOffset);
				if (endOffset == -1) {
					endOffset = document.cookie.length
				}
				return unescape(document.cookie.substring(startOffset, endOffset))
			}
		}
		return ""
	},//---------------------------------------------------------------------
	min: 9,
	max: 18,
	defaultSize: 9,
	size: null,
	p: null
};
/////////////////////////////////////////////////////////////////////////////
