/* For this function to work, the font-sizes in the website should be handled in % */
/*
+		changeFontSize(orgSize, changeSize, repeat, container)
+
+		orgSize 			= The original font-size used on the website wrapper
+		changeSize 			= the value of what the size should be changed to like 10 or -10
+		repeat 				= Should the value be changed more than once
+		container			= The id of the wrapper of the website
+		standard			= if set to true the font-size will return to standard font-size
*/
window.onload=function()
{
	initFontsize();
	initMenu();
}

function initFontsize()
{
	if (get_fontsize())
	{
		var cookiestr = get_fontsize();
		var increase = cookiestr.split("=")[1];
		increase = parseInt(increase);
		setCookieSize("wrapper", increase);
	}
}

function setCookieSize(container,new_fontsize)
{
	var base = document.getElementById(container);
	base.style.fontSize = new_fontsize+"%";
}

function get_fontsize()
{
	var str		= document.cookie;
	var key 	= "fontsize=";
	
	var start 	= str.indexOf(key, 0);
	
	if (start == -1)
		return false;
	else
	{
		var eind = str.indexOf(";", start);
		if (eind == -1) eind = str.length;
		return unescape(str.substring(start,eind));
	}
}

function changeFontSize(orgSize, changeSize, repeat, container, standard)
{
	if (standard == null) var standard = false;										// If parameter not given standard is false
	var base = document.getElementById(container);									// The base of the website on wich the primary font size is set
	var new_fontsize		=	null;												// The variable in wich the new fontsize will be specified
	
	if (base != null)
	{
		var cur_fontsize = base.style.fontSize;
		
		if (!standard)																// If standard is false then create the right fontsize
		{
			if (cur_fontsize == "")
			{
				new_fontsize = orgSize + changeSize;								//	The wrapper font-size is not set so this is the first time so its original + changesize
			}
			else
			{
				cur_fontsize = parseInt(base.style.fontSize.replace("%",""));		// The current aplied fontsize
				
				if (repeat)															// If repeat is true , always execute the font change
				{
					new_fontsize = cur_fontsize + changeSize;
				}
				else
				{
					var allowed_fontsize = orgSize + changeSize;					// Create the allowed font-size
					if (allowed_fontsize != cur_fontsize)							// If allowed size is different from current size then the size can change
						new_fontsize = cur_fontsize + changeSize;
					else
						new_fontsize = cur_fontsize;								// If allowed size is the same as current size then the size is the current size
				}
			}
		}
		else																		// If standard is true font-size is original size
			new_fontsize = orgSize;
		
		setCookie(new_fontsize);
		base.style.fontSize = new_fontsize+"%";										// Append the new font size to the site wrapper
	}
}

function setCookie(size)
{
	var today = new Date();
	var exp = new Date(today.getTime() + (365*24*60*60*1000));
	
	document.cookie = 'fontsize='+ size + ';expires='+ exp +';path=/';	
}