var FontSizer = new Class(
{		
	defaultOptions:
	{
		cookieName:   "FONT_SIZE_SETTING",
		cssPrefix:    "size",
		defaultValue: 0,
		maxValue:     3,
		onChange:     Class.empty
	},
	
	cookieOptions: 
	{
		duration: false,
		path: "/"
	},
	
	initialize: function(options)
	{
		this.options = Object.extend(this.defaultOptions, options);
		this.size = Cookie.get(this.options.cookieName) || this.options.defaultValue;
		this.size = Math.min(this.options.maxValue, 
			Math.max(0, this.size.toInt()));
			
		this.set();
	},
	
	set: function()
	{
		var pattern = /\s*size\d+\s*/;
		document.body.className = 
			(" " + document.body.className + " ").replace(pattern, " ").clean();
		document.body.className = (document.body.className + " " + 
			(this.options.cssPrefix + this.size)).clean();		
		Cookie.set(this.options.cookieName, this.size, this.cookieOptions);
		this.options.onChange(this);
	},
	
	increase: function()
	{
		this.size = Math.min(this.options.maxValue, this.size + 1);
		this.set();
	},
	
	decrease: function()
	{
		this.size = Math.max(0, this.size - 1);
		this.set();
	}
});

Window.onDomReady(function()
{
	var increaseButton = $("font_increase") ? 
		$("font_increase").getElementsByTagName("img")[0] : null;
	var decreaseButton = $("font_decrease") ? 
		$("font_decrease").getElementsByTagName("img")[0] : null;
	var PageFonts = new FontSizer(
	{
		onChange: function(fontSizer)
		{
			if(increaseButton && decreaseButton)
			{
				if(fontSizer.size >= fontSizer.options.maxValue)
				{
					increaseButton.src = increaseButton.src.replace(/_on.gif$/, '_off.gif');
				}
				else
				{
					increaseButton.src = increaseButton.src.replace(/_off.gif$/, '_on.gif');
				}
		
				if(fontSizer.size <= 0)
				{
					decreaseButton.src = decreaseButton.src.replace(/_on.gif$/, '_off.gif');
				}
				else
				{
					decreaseButton.src = decreaseButton.src.replace(/_off.gif$/, '_on.gif');
				}
			}
		}
	});

	if(increaseButton && decreaseButton)
	{
		$("font_increase").onclick = function() { PageFonts.increase(); return false; };
		$("font_decrease").onclick = function() { PageFonts.decrease(); return false; };
	}
});