var fontSizeMin = 8;
var fontSizeMax = 18;
var fontSizeDefault = 11;

$('body').ready(function(){
	adjustFontSize(null);
});

$(function(){
	$('#resizeUp').click(function(){
		adjustFontSize('up');
	});
	$('#resizeDown').click(function(){
		adjustFontSize('down');
	});
});

function adjustFontSize(dir)
{
	var curSize = parseInt(getFontSizeCookie());
	if(curSize == 'undefined' || curSize == null || isNaN(curSize) || curSize < fontSizeMin || curSize > fontSizeMax){
		curSize = fontSizeDefault;
	}
	if(dir == 'up')
	{
		if(++curSize > fontSizeMax)
		{
			curSize = fontSizeMax;
		}
	}
	if(dir == 'down')
	{
		if(--curSize < fontSizeMin)
		{
			curSize = fontSizeMin;
		}
	}
	document.body.style.fontSize = curSize + 'px';
	setFontSizeCookie(curSize,3);
}

function getFontSizeCookie(){
	var cName = 'siteFontSize';
	if(document.cookie.length > 0){
		var cStart = document.cookie.indexOf(cName + '=');
		if(cStart >= 0){
			cStart += cName.length + 1;
			cEnd = document.cookie.indexOf(';',cStart);
			if(cEnd == -1){
				cEnd = document.cookie.length;
			}
			return unescape(document.cookie.substring(cStart,cEnd));
		}
	}
	return;
}
function setFontSizeCookie(cookieValue,nDays){
	var today = new Date();
	var expires = new Date();
	if(nDays == null || nDays == 0){
		nDays = 1;
	}
	expires.setTime(today.getTime() + 3600000 * 24 * nDays);
	document.cookie = 'siteFontSize=' + escape(cookieValue) + ';expires=' + expires.toGMTString() + ';path=/';
}
