$(document).ready(function()
{
	var textSizes = new Array('12px', '14px', '16px', '18px');
	var currentTextSize = 0;

	initFontSize();

	// Increase Font Size
	$('.increaseFont').click(function()
	{
		if ( currentTextSize + 1 < 0 || currentTextSize + 1 >= textSizes.length )
			return;
		currentTextSize = currentTextSize + 1;
		setFontSize(currentTextSize);
	});

	// Decrease Font Size
	$('.decreaseFont').click(function()
	{
		if ( currentTextSize - 1 < 0 || currentTextSize - 1 >= textSizes.length )
			return;
		currentTextSize = currentTextSize - 1;
		setFontSize(currentTextSize);
	});

	function initFontSize() 
	{
		if (document.cookie) 
		{
			var value = getCookie("baybw_fontsize");	

			if(value != null)
			{
				currentTextSize = parseInt(value);
				setFontSize(value);
			}
		}
	}

	function setFontSize(value) 
	{
		var body = document.getElementsByTagName('body')[0];
		body.style.fontSize = textSizes[value];
		
		document.cookie = "baybw_fontsize=" + value + "; path=/";
	}

	/* 
	 * Ermittelt Inhalt eines namentlich bezeichneten Cookies.
	 */
	function getCookie(name)
	{
		var bezeichner = name + "=";
		var laenge = bezeichner.length;
		var cookie_laenge = document.cookie.length;
		var i = 0;
		while (i < cookie_laenge)
		{
			var j = i + laenge;
			if (document.cookie.substring(i, j) == bezeichner)
			{
				return getCookieValue(j);
			}
			i = document.cookie.indexOf(" ", i) + 1;
			if (i == 0)
			{
				break;
			}
		}
		return null;
	}

	function getCookieValue(position)
	{
		var ende = document.cookie.indexOf(";", position);
		if (ende == -1)
			ende = document.cookie.length;
		return unescape(document.cookie.substring(position,ende));
	}
});

