standardFont = "fonts/arial.mvec";
oldsansblackFont = "fonts/oldsansblack.mvec";
trebuchetmsFont = "fonts/trebuchetms.mvec";
minionproFont = "fonts/minionpro.mvec";
certegeFont = "fonts/certege.mvec";

BlackColor = Color(0,0,0,255);
BlueColor = Color(77,115,178,255);
DarkBlueColor = Color(40,60,120,255);
WhiteColor = Color(255,255,255,255);
MenuButtonFontColor = Color(255,255,255,255);
RedTextColor = Color(122,0,0,255);
RedNotSelectedTextColor = Color(181,126,126,255);
TeamWorkListColor = Color(229,187,77,255);

CheckboxButtonGraphics = {
	"buttons/check_up",
	"buttons/check_down",
	"buttons/check_over",
	"buttons/check_downover"
};

SmallMainMenuButtonGraphics = {
	"buttons/smallbutton_main_menu_up",
	"buttons/smallbutton_main_menu_down",
	"buttons/smallbutton_main_menu_over"
};

SmallButton1Graphics = {
	"buttons/smallbutton1_up",
	"buttons/smallbutton1_down",
	"buttons/smallbutton1_over"
};

SmallButton2Graphics = {
	"buttons/smallbutton2_up",
	"buttons/smallbutton2_down",
	"buttons/smallbutton2_over"
};

MediumButton1Graphics = {
	"buttons/mediumbutton1_up",
	"buttons/mediumbutton1_down",
	"buttons/mediumbutton1_over"
};

MediumButton2Graphics = {
	"buttons/mediumbutton2_up",
	"buttons/mediumbutton2_down",
	"buttons/mediumbutton2_over"
};

BigButtonGraphics = {
	"buttons/bigbutton_up",
	"buttons/bigbutton_down",
	"buttons/bigbutton_over"
};

StandardButtonFont = {
  standardFont,
  18,
  BlackColor
};

MenuButtonFont = {
  standardFont,
  22,
  MenuButtonFontColor
};

UIFont = 
{
  standardFont,
  20,
  WhiteColor
}

DialogTitleFont = {
  standardFont,
  20,
  BlackColor
};

DialogBodyFont = {
  standardFont,
  18,
  BlackColor
};

DefaultStyle = {
	font=DialogBodyFont
};

DialogTitleText = {
	parent=DefaultStyle,
	font = DialogTitleFont,
	flags = kVAlignCenter + kHAlignLeft,
	x=16,y=12,w=kMax,h=30
};

DialogBodyText = {
	parent=DefaultStyle,
	font = DialogBodyFont,
	flags = kVAlignCenter + kHAlignCenter,
	x=0,y=46,w=kMax,h=kMax-60
};

SliderStyle =
{
	parent=DefaultStyle,
	railtop = "gui/customoptions/sliderrailtop",
	railmid = "gui/customoptions/sliderrailmid",
	railbot = "gui/customoptions/sliderrailbot",
	sliderimage = "gui/customoptions/sliderknob",
	sliderrollimage = "gui/customoptions/sliderknobover",

	yoffset = -1, -- scoot the slider down by one pixel to center it.
};

kDefaultButtonSound="audio/sfx/buttonclick.ogg";

MenuButtonGraphics = {
	"",
	"gui/mainmenu/selected",
	"gui/mainmenu/selected",
};

MenuButtonStyle = {
	sound = "audio/sfx/buttons/mouse_click",
	rolloversound = "audio/sfx/buttons/mouse_over.ogg",
};

MenuButtonStyleOld = {
	parent = DefaultStyle,
	font = DialogBodyFont,
	sound = "audio/sfx/buttons/mouse_click",
	rolloversound = "audio/sfx/buttons/mouse_over.ogg",
	graphics = {},
	w=169, h=40
};

MenuButtonStyleNOLINE = {
	parent = DefaultStyle,
	font = MenuButtonFont,
	sound = kDefaultButtonSound,
	graphics = {},
	w=169, h=40

};

CheckboxButtonStyle = {
	parent = DefaultStyle,
	font = StandardButtonFont,
	type = kToggle,
	sound = kDefaultButtonSound,
	graphics = CheckboxButtonGraphics,
};

SetDefaultStyle(DefaultStyle);

-- Create a TButton with a label
--
-- We're overriding the default "Button" here with
-- some custom behavior. Specifically, we're layering
-- a Text{} object on top of every button, and it's placed
-- on all layers (up, down, roll-over).
function Button( button )
	return function()
		-- Grab the label from the button or current style
		if (GetTag(button,"label")) then

			-- Look for text dimensions
			local tx = GetTag(button,"tx");
			local ty = GetTag(button,"ty");
			local tw = GetTag(button,"tw");
			local th = GetTag(button,"th");

			-- Set defaults
			if (not tx) then
				tx = 0;
			end
			if (not ty) then
				ty = 0;
			end
			if (not tw) then
				tw=kMax ;
			end
			if (not th) then
				th=kMax ;
			end

			-- Get the label
			local label = GetTag(button,"label");

			local defflags = kPushButtonAlignment ;
			if (GetTag(button,"type")==kToggle) then
				defflags = kToggleButtonAlignment ;
			elseif (GetTag(button,"type")==kRadio) then
				defflags = kRadioButtonAlignment ;
			end

			local textfactory = GetTag(button,"textfactory");
			if (not textfactory) then
				textfactory = "_text"
			end
			table.insert(button,
				SelectLayer( kAllLayers )
			);
			-- Grow our window to encompass any children we've added
			-- already.
			table.insert(button,
				FitToChildren()
			);

			table.insert(button,
				AppendStyle{ font=button.font; flags=button.flags; }
			);

			table.insert(button,
				Text
				{
					label=label,
					x=tx, y=ty, w=tw, h=th,
					name='label',
					defflags =defflags
				}
			)
		end

		-- Type name of window to create; in our case, "Button".
		-- If you want to create a derived button type, you can do that here.
		button.typename='Button';
		DoWindow( button )
	end
end

function Calendar(x, y, day)	
	local calendar = {
				name="day"..day,
				image="gui/commons/calendar",
				image="gui/commons/calendar",
				x=x,
				y=y,
				Text
				{
					font = {
						oldsansblackFont,
						13,
						BlackColor
					},
					x = 15,
					y = 12,
					w = 26,
					h = 13,
					flags = kHAlignCenter,
					label = "day",
				},	
				
				Text
				{
					name = "day",
					font = DayTextFont,		
					x=22,
					y=33,
					w=60,
					h=60,
					flags = kHAlignLeft + kVAlignTop,
					label="#<b><i>"..day.."</b></i>"
				},
			};
	 return calendar;
end

function GrayCalendar(x, y, day)	
	local calendar = {
				image="gui/commons/gray_calendar",
				x=x,
				y=y,
				fit = true,
				Text
				{
					font = {
						oldsansblackFont,
						13,
						Color(158,143,114,255)
					},
					x = 15,
					y = 12,
					w = 26,
					h = 13,
					flags = kHAlignCenter,
					label = "day",
				},	
				
				Text
				{
					name = "day",
					font = {
						oldsansblackFont,
						13,
						Color(158,143,114,255)
					},
					x=22,
					y=33,
					w=60,
					h=60,
					flags = kHAlignLeft + kVAlignTop,
					label="#<b><i>"..day.."</b></i>"
				},
			};
	 return calendar;
end	

function FamilySymbol(x, y, familynumber)	
	local familysymbol = 
		{
			name = "familyphoto"..familynumber,
			image = "gui/commons/family"..familynumber,
			x=x,
			y=y,
			--[[
			Text
			{
				name = "familyname",
				x = 9,
				y = 53,
				w = 758,
				h = 106,
				font = {
					oldsansblackFont,
					12,
					BlackColor
				},
				label = "family"..familynumber,
			},
			--]]
		};
	 return familysymbol;
end

function Balloon(x, y, text)	
	local balloon = 
		{
			name = text,
			image = "gui/commons/new",
			x=x,
			y=y,
			w=54,
			h=38,
			Text
			{
				x = 10,
				y = 10,
				w = 758,
				h = 106,
				font = {
					oldsansblackFont,
					14,
					BlackColor
				},
				label = text,
			},
		};
	 return balloon;
end

function DayButton(x, y, day)	
	local dayButton = 
		{
			name = "daybutton"..day,
			x=x,
			y=y,
			w=55,
			h=57,
			command=
				function()
					SelectDay(day);
				end
		};
	 return dayButton;
end

function FamilyButton(x, y, family)	
	local familyButton = 
		{
			name = "familybutton"..family,
			x=x,
			y=y,
			w=269,
			h=84,
			command=
				function()
					SelectFamily(family);
				end
		};
	 return familyButton;
end

-- Create several bits of text that combine to make a blended shadow
function ColorShadowText( x,y,size, label, color )

	return Group(
		{
		-- Add these traits to the current style
			AppendStyle{ x=x, y=y, w=kMax, h=kMax, label=label },
			AppendStyle{ font = { standardFont, size, Color(0,0,0,40)} },
			Text{ y=y+4 },
			AppendStyle{ font = { standardFont, size, Color(0,0,0,255)} },
			Text{ y=y+2 },
			AppendStyle{ font = { standardFont, size, color } } ,
			Text{},
		}
	)
end

function TextOutlined(color, bordersize, text)
	return "<outline color='"..color.."' size='"..bordersize.."'>"..text.."</outline>"
end

kMenuButtonFontSize = 22;

--function MenuButtonLabel(x, y, newx, newy, label, font, size, color, colorDown, colorOver )
function MenuButtonLabel(x, y, width, height, label, font, size, color, colorDown, colorOver )
	if not color then
		color =Color(192,207,255,255);	-- the default colors
		colorHighlight=Color(255,255,255,255)
	end

	return Group{
		--AppendStyle{ x=0, y=0, w=kMax, h=kMax, label=label},
		AppendStyle{ x=x, y=y, w=width, h=height, label=label},
		SelectLayer(0),
		Text{font = {font, size, color}, flags = kHAlignCenter+kVAlignCenter},
		SelectLayer(1),
		--Text{x=newx, y=newy, font = {font, size, colorDown}, flags = kHAlignCenter+kVAlignCenter},
		Text{font = {font, size, colorDown}, flags = kHAlignCenter+kVAlignCenter},
		SelectLayer(2),
		Text{font = {font, size, colorOver}, flags = kHAlignCenter+kVAlignCenter},
		SelectLayer(kAllLayers),		
	}

end

function MenuButtonLabelOld( label, color, colorHighlight, fontSize)
	--GetString("textoutlined", "options");
	return Group{
		SelectLayer(0),
		AppendStyle{ font = { oldsansblackFont , fontSize, color } },
		Text{x = 0, w=kMax, h=kMax, label=label, flags = kHAlignLeft+kVAlignCenter, font = {font, fontSize, color} },
		SelectLayer(1),
		Text{x = 20, w=kMax, h=kMax, label=label, flags = kHAlignLeft+kVAlignCenter, font = {font, fontSize, colorHighlight} },
		SelectLayer(2),
		Text{x = 10, w=kMax, h=kMax, label=label, flags = kHAlignLeft+kVAlignCenter, font = {font, fontSize, colorHighlight} },
		SelectLayer(3),
		Text{x = 20, w=kMax, h=kMax, label=label, flags = kHAlignLeft+kVAlignCenter, font = {font, fontSize, colorHighlight} },
	}

end

-- Create a more limited-use button type here; the label is defined inline
-- with MenuButtonLabel above
function MenuButton( button )
	return function()
		-- Type name of window to create; in our case, "Button".
		-- If you want to create a derived button type, you can do that here.
		button.typename='Button';
		DoWindow( button )
	end
end

kIllegalNameChars = "!@#$%^&*()><\\\"\'[]{}|?/+=~`.,;:-_ ";