﻿TextSize = new Object();
TextSize.CurrentKey = "CurrentTextSize";
TextSize.Default = 11;

// decreases the text size
TextSize.Decrease = function()
{
	TextSize.SetCurrent(TextSize.Current - 1);
}

// gets the text size from the user's cookie
TextSize.GetCurrent = function()
{
	if (TextSize.Cookies == null)
	{
		TextSize.Cookies = TextSize.ParseCookies();
	}
	
	var cookie = TextSize.Cookies[TextSize.CurrentKey];
	
	if (cookie && cookie != "")
	{
		return parseInt(cookie);
	}
	
	return TextSize.Default;
}

// increases the text size
TextSize.Increase = function()
{
	TextSize.SetCurrent(TextSize.Current + 1);
}

// parses the document cookie and returns a set of key/value pairs
TextSize.ParseCookies = function()
{
	var cookies = new Array();
	
	if (document.cookie && document.cookie != "")
	{
		var entryList = document.cookie.split("; ");
		
		for (var i = 0; i < entryList.length; i++)
		{
			var entry = entryList[i].split("=");
			
			if (entry.length == 2)
			{
				cookies[entry[0]] = entry[1];
			}
		}
	}
	
	return cookies;
}

// sets the document's text size
TextSize.SetCurrent = function(size)
{
	if (document.body && document.body.style)
	{
		document.body.style.fontSize = size + "px";
		
		TextSize.Current = parseInt(size);

		if (document.cookie)
		{
			document.cookie = TextSize.CurrentKey + "=" + TextSize.Current;
		}
	}
}

function SetSidebarSize()
{
	if (document.getElementById)
	{
		var sidebar = document.getElementById("MainSidebar");
		
		if (sidebar && sidebar.parentNode)
		{
			sidebar.style.height = sidebar.parentNode.offsetHeight + "px";
		}
	}
}

// initialize
TextSize.Cookies = TextSize.ParseCookies();
TextSize.Current = TextSize.GetCurrent();

window.setInterval(SetSidebarSize, 1000);
