FacebookButtonClickSound = "facebook/common/button_click";
FacebookButtonRolloverSound = "facebook/common/button_rollover";

dofile("facebook/game/facebook_globals.lua");

FacebookWhiteColor = Color(255,255,255,255);
FacebookBlackColor = Color(0,0,0,255);

FacebookFontFileBold = "facebook/common/helvetica_b.mvec";
FacebookFontFile = "facebook/common/helvetica.mvec";

FacebookDetailFont = 
{
	FacebookFontFile,
	12,
	FacebookWhiteColor,
};

FacebookEditFont = 
{
	FacebookFontFile,
	12,
	FacebookBlackColor,
};

FacebookButtonFont = 
{
	FacebookFontFileBold,
	18,
	FacebookWhiteColor,
};

FacebookBodyFont = 
{
	FacebookFontFileBold,
	14,
	FacebookWhiteColor,
};

FacebookTitleFont = 
{
	FacebookFontFileBold,
	20,
	FacebookWhiteColor,
};

FacebookOkayButtonGraphics =
{
	"facebook/common/fb_ok_btn_up",
	"facebook/common/fb_ok_btn_down",
	"facebook/common/fb_ok_btn_rollover",
};

FacebookPostButtonGraphics =
{
	"facebook/common/fb_post_btn_up",
	"facebook/common/fb_post_btn_down",
	"facebook/common/fb_post_btn_rollover",
};

FacebookNoThanksButtonGraphics =
{
	"facebook/common/fb_no_btn_up",
	"facebook/common/fb_no_btn_down",
	"facebook/common/fb_no_btn_rollover",
};


FacebookNoButtonGraphics =
{
	"facebook/common/fb_no2_btn_up",
	"facebook/common/fb_no2_btn_down",
	"facebook/common/fb_no2_btn_rollover",
};

FacebookYesButtonGraphics =
{
	"facebook/common/fb_yes_btn_up",
	"facebook/common/fb_yes_btn_down",
	"facebook/common/fb_yes_btn_rollover",
};


FacebookGreyButtonGraphics =
{
	"facebook/common/fb_share_gray_btn_up",
	"facebook/common/fb_share_gray_btn_down",
	"facebook/common/fb_share_gray_btn_rollover",
};

FacebookBlueButtonGraphics =
{
	"facebook/common/fb_share_blue_btn_up",
	"facebook/common/fb_share_blue_btn_down",
	"facebook/common/fb_share_blue_btn_rollover",
};

FacebookButtonStyle =
{
	x = kCenter,
	font = FacebookButtonFont,
	sound = FacebookButtonClickSound,  
	rolloversound = FacebookButtonRolloverSound,
};

FacebookOkayButtonStyle =
{
	parent = FacebookButtonStyle,
	graphics = FacebookOkayButtonGraphics,
};

FacebookBlueButtonStyle =
{
	parent = FacebookButtonStyle,
	graphics = FacebookBlueButtonGraphics,
};

FacebookPostButtonStyle =
{
	parent = FacebookButtonStyle,
	graphics = FacebookPostButtonGraphics,
};

FacebookNoThanksButtonStyle =
{
	parent = FacebookButtonStyle,
	graphics = FacebookNoThanksButtonGraphics,
	cancel = true,
};


FacebookYesButtonStyle =
{
	parent = FacebookButtonStyle,
	graphics = FacebookYesButtonGraphics,
};

FacebookNoButtonStyle =
{
	parent = FacebookButtonStyle,
	graphics = FacebookNoButtonGraphics,
	cancel = true,
};


FacebookCheckboxButtonStyle =
{
	parent = FacebookButtonStyle,
	type = kToggle,
	graphics = 
	{
		"facebook/common/fb_uncheck.png",
		"facebook/common/fb_checked.png",
		"facebook/common/fb_uncheck.png",
		"facebook/common/fb_checked.png",
	},
};

FacebookGreyButtonStyle =
{
	parent = FacebookButtonStyle,
	graphics = FacebookGreyButtonGraphics,
};

-- 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 FBButton( 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");
			local fonts = GetTag(button,"fonts");

			-- 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

			if (fonts == nil) then
				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
					}
				)
			else
				for i=0,3 do
					
					table.insert(button,
						SelectLayer( i )
					);
					-- Grow our window to encompass any children we've added
					-- already.
					table.insert(button,
						FitToChildren()
					);

					table.insert(button,
						AppendStyle{ flags=button.flags; }
					);
					
					local fontIndex = i+1;
					if (fontIndex > table.getn(fonts)) then
						fontIndex = table.getn(fonts);
					end
					
					table.insert(button,
						Text
						{
							label=label,
							x=tx, y=ty, w=tw, h=th,
							font = fonts[fontIndex],
							name='label',
							defflags =defflags
						}
					);
				end
			end
		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
