function GetLocal()
	if(GetState() =="viewing_winery") then
		return "winery";
	
	elseif(GetState() =="viewing_cellar") then
		return "cellar";
	
	elseif(GetState() =="viewing_supplier") then
		return "supplier";
	
	elseif(GetState() =="viewing_worldmap") then
		return "worldmap";		
	
	elseif(GetState() == "viewing_scene") then
		return "scene";
		
	elseif(GetState() == "viewing_guild") then
		return "guild";

	else 
		return "###"
	
	end
end

function verifySupplies(grapeA, qtyA, grapeB, qtyB, bottle, bottleQty)
	if(GetSeedQnt(grapeA) < qtyA or	GetSeedQnt(grapeB) < qtyB or GetSupplyQnt(bottle) < bottleQty) then
		return false;
	else
		return true;
	end
end

standardFont = "fonts/cbox.mvec";
stdLegibleFont = "fonts/temporarium.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);
DarkGreenColor = Color(19,53,23,255);
MenuButtonFontColor = Color(0,0,0,255);

StandardButtonGraphics = {
	"buttons/buttonup",
	"buttons/buttondown",
	"buttons/buttonrollover"
};

StandardButtonYesGraphics = {
	"buttons/stdyes"
};

StandardButtonDoneGraphics = {
	"buttons/stddone",
    "buttons/stddonedown",
    "buttons/stddoneover"
};

StandardButtonCancelGraphics = {
	"buttons/stdcancel",
    "buttons/stdcanceldown",
    "buttons/stdcancelover",
};

ButtonCancelStyle = {
	parent = DefaultStyle,
	sound = kDefaultButtonSound,
	type= kPush,
	face = "buttons/stdcancel",
	shadow = "buttons/stddone_shadow",
	displacement = 2,

};

ButtonStdCancelStyle = {
	parent = DefaultStyle,
	sound = kDefaultButtonSound,
	type= kPush,
	graphics = 
	{
		"buttons/stdcancel",
		"buttons/stdcanceldown",
		"buttons/stdcancelover",
	},
	font = StandardButtonFont,
};

StandardButtonNoGraphics = {
	"buttons/stdno"
};

StandardButtonOkGraphics = {
	"buttons/stdok"
};

LongButtonGraphics = {
	"buttons/long_button_up.png"
};

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

CheckboxButtonGraphics = {
	"buttons/checkup",
	"buttons/checkdown",
	"buttons/checkover",
	"buttons/checkdownover"
};

StandardButtonFont = {
  standardFont,
  26,
  WhiteColor
};

ButtonYesFont = {
  standardFont,
  34,
  WhiteColor
};

MenuButtonFont = {
  standardFont,
  30,
  MenuButtonFontColor
};

ShipAddFontStyle = stdLegibleFont;

ShipAddButtonFont = {
  ShipAddFontStyle,
  10,
  WhiteColor
};

DialogTitleFont = {
  standardFont,
  22,
  BlackColor
};

DialogBodyFont = {
  stdLegibleFont,
  20,
  BlackColor
};

MenuFont = {
  standardFont,
  26,
  BlackColor
};

ProfileFont = {
  standardFont,
  22,
  DarkGreenColor
};

MenuStyle = {
	font=MenuFont
};

DefaultStyle = {
	font=DialogBodyFont,
	allowInput=true,
};

MenuProfileStyle = {
	font=ProfileFont
};

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

DialogBodyText = {
	parent=DefaultStyle,
	font = DialogBodyFont,
	flags = kHAlignCenter + kVAlignCenter,
	x=48,y=64,w=kMax-64,h=kMax-110,
};

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

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

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

MenuButtonStyle = {
	parent = DefaultStyle,
	font = MenuButtonFont,
	sound = kDefaultButtonSound,
	rolloversound = "audio/sfx/buttons/menu_over.ogg",
	graphics = MenuButtonGraphics,
	flags = kVAlignTop + kHAlignCenter,
	w=155, h=40
};

EmptyButtonStyle = {
	parent = DefaultStyle,
	font = StandardButtonFont,
	sound = kDefaultButtonSound,
	type= kPush,
};

ButtonStyle = {
	parent = DefaultStyle,
	font = StandardButtonFont,
	sound = kDefaultButtonSound,
	type= kPush,
	graphics = StandardButtonGraphics,
};

LongButtonStyle = {
	parent = DefaultStyle,
	font = StandardButtonFont,
	sound = kDefaultButtonSound,
	type= kPush,
	graphics = LongButtonGraphics,
};


ButtonOkStyle = {
	parent = DefaultStyle,
	sound = kDefaultButtonSound,
	type= kPush,
	face = "buttons/stdok",
	shadow = "buttons/stddone_shadow",
	displacement = 2,
	font = StandardButtonFont,
};

ButtonStdOkStyle = {
	parent = DefaultStyle,
	sound = kDefaultButtonSound,
	type= kPush,
	graphics = 
	{
		"buttons/blueidle",
		"buttons/bluedown",
		"buttons/blueover",
	},
	font = StandardButtonFont,
};

ButtonYesStyle = {
	parent = DefaultStyle,
	font = ButtonYesFont,
	sound = kDefaultButtonSound,
	type= kPush,
	displacement = 2,
	face = "buttons/stddone",
	shadow = "buttons/stddone_shadow"
};

ButtonNoStyle = {
	parent = DefaultStyle,
	font = {
			standardFont,
			20,
			WhiteColor
			},
	sound = kDefaultButtonSound,
	type= kPush,
	face = "buttons/stdno",
	shadow = "buttons/stddone_shadow",
	displacement = 2,
};

LongButtonStyle = {
	parent = ButtonStyle,
	--graphics = LongButtonGraphics
	face = "buttons/long_button_up.png",
	displacement = 2,
	sound = "audio/sfx/buttons/default_click.ogg",
};

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

StarButtonStyle = {
	parent = DefaultStyle,
	font = MenuButtonFont,
	sound = kDefaultButtonSound,
	graphics = {"minigame3/blank_star.png", "minigame3/full_star.png", "minigame3/blank_star.png", "minigame3/full_star.png"},
	--flags = kVAlignTop + kHAlignCenter,
	type= kPush,
	tx=0, ty=0,tw=40, th=40
};

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

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

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

kMenuButtonFontSize = 26;
kShipAddButtonFontSize = 15;

function MenuButtonLabel( label, color, colorHighlight)

	if not color then
		color =Color(0,0,0,255);
		colorHighlight=Color(255,255,255,255)
	end
	
	return Group{
		SelectLayer(0),
		ColorShadowText(5,1,kMenuButtonFontSize, label, color ),
		SelectLayer(1),
		ColorShadowText(5,1,kMenuButtonFontSize, label, color ),
		SelectLayer(2),
		ColorShadowText(5,1,kMenuButtonFontSize, label, color )
	}
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 = "!@#$%^&*()><\\\"\'[]{}|?/+=~`.,;:-";

function AddButton( button )
	return function()
		button.typename='Button';
		DoWindow( button )
	end
end


AddButtonStyle = {
	parent = DefaultStyle,
	font = ShipAddButtonFont,
	type= kPush,
	close = false,
	flags = 5,
	displacement = 1,
};