// font resize
function fontResize(font_size)
{
	var font_size = font_size.toInt();
	var content_node = $('content');
	
	// set new font-size
	content_node.setStyle('font-size', font_size+'px');
	
	// set cookie
	setCookie('fontSize', font_size, 365);
}

// set cookie
function setCookie(c_name, value, expiredays)
{
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+
	((expiredays==null) ? "" : ";expires="+exdate.toGMTString()+";path=/");
}

// get cookie
function getCookie(c_name)
{
	if (document.cookie.length>0)
	{
		c_start=document.cookie.indexOf(c_name + "=");
		if (c_start!=-1)
		{ 
			c_start=c_start + c_name.length+1; 
			c_end=document.cookie.indexOf(";",c_start);
			if (c_end==-1) c_end=document.cookie.length;
			return unescape(document.cookie.substring(c_start,c_end));
		} 
	}
	
	return "";
}

// check cookie
function checkCookie()
{
	var font_size = getCookie('fontSize');
	
	if (font_size != null && font_size != "")
	{
		fontResize(font_size);
	}
}

// resize submenu columns
function resizeSubMenuColumns()
{
	var menu_parent	= $('menu');
	var ul_node		= menu_parent.getElement('ul');
	
	if(ul_node)
	{
		var li_nodes		= ul_node.getChildren('li');
		var total_li_nodes	= li_nodes.length;
		
		if(total_li_nodes > 0)
		{
			li_nodes.each(function(li_node)
			{
				var ul_subnode = li_node.getElement('ul');
				
				if(ul_subnode)
				{
					var li_subnodes			= ul_subnode.getChildren('li');
					var total_li_subnodes	= li_subnodes.length;
					
					if(total_li_subnodes > 0)
					{
						// set vars
						var column_counter				= 1;
						var array_index					= 0;
						var submenu_columns				= 4;
						var biggest_column_height		= 0;
						var arr_column_height			= new Array();
						arr_column_height[array_index]	= biggest_column_height;
						
						// get biggest height per column								
						li_subnodes.each(function(li_subnode)
						{
							var li_subnode_coordinates	= li_subnode.getCoordinates();
							var li_subnode_height		= li_subnode_coordinates.height.toInt();
							
							if (li_subnode_height > arr_column_height[array_index])
							{
								arr_column_height[array_index]	= li_subnode_height;
							}
							
							column_counter++;
							
							if (column_counter > submenu_columns)
							{
								array_index++;
								biggest_column_height			= 0;
								column_counter					= 1;
								arr_column_height[array_index]	= biggest_column_height;
							}
						});
						
						// set height sub ul node
						var total_columns_height = 0;
						
						arr_column_height.each(function(column_height)
						{
							total_columns_height = total_columns_height + column_height;
						});
						
						ul_subnode.setStyle('height', total_columns_height+'px');
					}
					
					var column_counter_new		= 1;
					var array_index_new			= 0;
					var li_subnodes_new			= ul_subnode.getChildren('li');
					var total_li_subnodes_new	= li_subnodes_new.length;
					
					if(total_li_subnodes_new > 0)
					{
						// get biggest height per column								
						li_subnodes_new.each(function(li_subnode_new)
						{
							li_subnode_new.setStyle('height', arr_column_height[array_index_new]+'px');
							
							column_counter_new++;
							
							if (column_counter_new > submenu_columns)
							{
								array_index_new++;
								column_counter_new = 1;
							}
						});
					}
				}
			});
		};
	};
}
