BEMB = {
	version = GetAddOnMetadata("BEMB", "Version");
	revision = tonumber(("$Revision: 20 $"):match("%d+"));
	date = ("$Date: 2010-10-14 15:40:44 +0000 (Thu, 14 Oct 2010) $"):match("%d%d%d%d%-%d%d%-%d%d");
	-- more data coming 
--[===[@alpha@
	debugv = true;
--@end-alpha@]===]
}
BEMB.versionstring = BEMB.version .. "r" .. BEMB.revision;

-- [[ caching global variables into locals ]]
local BEMB = BEMB;
local debugv = BEMB.debugv;
local self = BEMB;

--[[ Localisation ]]
if GetLocale() == "deDE" then
	BEMB_CLOSE = "Men\195\188 schlie\195\159en";
	BEMB_REFRESH = "Sets aktualisieren";
	BEMB_NOSETS = "Keine Sets gefunden";
	BEMB_ENABLE = "Ausr\195\188stungsmanager aktivieren";
	BEMB_SHOW = "Ausr\195\188stungsmanager anzeigen";
	BEMB_INFO = "Infos";
	BEMB_SEE_LICENSE_TXT = "Weitere Lizenzdetails befinden sich in der Datei license.txt";
	BEMB_FIND_BUGS = "Solltest du einen Fehler finden, melde ihn bitte an mich.";
	BEMB_DATE = ", ver\195\182ffentlicht am: "; 
else
	BEMB_CLOSE = "Close menu";
	BEMB_REFRESH = "Refresh sets";
	BEMB_NOSETS = "There are no sets";
	BEMB_ENABLE = "Enable EquipmentManager";
	BEMB_SHOW = "Show GearManager";
	BEMB_INFO = "Info";
	BEMB_SEE_LICENSE_TXT = "See license.txt for license details";
	BEMB_FIND_BUGS = "If you find any bugs, please report them to me";
	BEMB_DATE = ", released at: ";
end;

--[[ Debug mode ]]
--[===[@alpha@
if debugv then 
	SlashCmdList['BEMB_SLASHCMD'] = function(msg)
		print(msg);
	end;
	SLASH_BEMB_SLASHCMD1 = '/print';
	
	SlashCmdList['INDEX_SLASHCMD'] = function(msg)
		if strtrim(msg) ~= "" then 
			msg = tonumber(msg);
			_, icon, _ = GetEquipmentSetInfo(msg);
			print(GetTextureIndex(icon));
		end;
	end;
	SLASH_INDEX_SLASHCMD1 = '/texture';
end;
--@end-alpha@]===]

--[[ Similar to the addon:Print() function of Ace, but also prints set list, if no arguments are specified ]]
function BEMB:Print(text)
	if not text then
--		BEMB_GetEquipmentSets()
		for i=1,GetNumEquipmentSets() do
			local name, icon, _ = GetEquipmentSetInfo(i);
			print("|cFF00FF00BEMB: |rName of set "..i..": "..name);
			print("|cFF00FF00BEMB: |rIcon of set "..i..": \124T"..icon..":16\124t ");
		end
	else
		print("|cFF00FF00BEMB: |r"..text);
	end;
end;

--[[ OnLoad function ]]
function BEMB_OnLoad()
	BEMBDB = {
		MinimapPos = 180 -- default position of the minimap icon in degrees
	}
end;

--[[ Button movement function ]]
function BEMB_MinimapButton_Reposition()
	BEMB_MinimapButton:SetPoint("TOPLEFT","Minimap","TOPLEFT",52-(80*cos(BEMBDB.MinimapPos)),(80*sin(BEMBDB.MinimapPos))-52)
end

--[[ What happens, when button is moved ]]
function BEMB_MinimapButton_DraggingFrame_OnUpdate()

	local xpos,ypos = GetCursorPosition()
	local xmin,ymin = Minimap:GetLeft(), Minimap:GetBottom()

	xpos = xmin-xpos/UIParent:GetScale()+70 -- get coordinates as differences from the center of the minimap
	ypos = ypos/UIParent:GetScale()-ymin-70

	BEMBDB.MinimapPos = math.deg(math.atan2(ypos,xpos)) -- save the degrees we are relative to the minimap center
	BEMB_MinimapButton_Reposition() -- move the button
end

--[[ Click on the button ]]
function BEMB_MinimapButton_OnClick(button)
	if button == "LeftButton" then
		ToggleDropDownMenu(1, nil, BEMB_DropDown, BEMB_MinimapButton, 0, 0);
	elseif button == "RightButton" then
		BEMB:Print();
	end;
end;

--[[ Equips the equipment set and changes the minimap button texture ]]
function BEMB_UseEquipmentSet(name, id)
	UseEquipmentSet(name);
	local _, icon, _ = GetEquipmentSetInfo(id);
	BEMB_MinimapButton_Icon:SetTexture(icon);
end;

--[[ Click on one of the options in the drop down menu ]]
function BEMB_DropDown_Click(self)
	local button = self.value;
	if button == "refresh" then
--		BEMB_GetEquipmentSets()
	end;
	for i=1, GetNumEquipmentSets() do
		local name, _, _ = GetEquipmentSetInfo(i);
		if button == "equipset "..i then
			BEMB_UseEquipmentSet(name, i)
		end;
	end;
	if button == "showgm" then 
		GearManagerDialog:SetParent("UIParent")
		GearManagerDialog:Show()
	end;
	if button == "enablegm" then 
		SetCVar("equipmentManager", 1);
		GearManagerToggleButton:Show();
	end;
	if button == "info" then
		BEMB:Print("####");
		BEMB:Print("(c) 2009 T. Saul a.k.a. laroawen");
		BEMB:Print(BEMB_SEE_LICENSE_TXT);
		BEMB:Print("Version: " .. BEMB.versionstring .. BEMB_DATE .. BEMB.date);
		BEMB:Print(BEMB_FIND_BUGS);
		BEMB:Print("####");

	end;
end;

--[[ Creates the drop down menu ]]
function BEMB_DropDown_OnLoad()
	info = {}; -- Bem-Button
	info.text = "BEM-Button";
	info.notCheckable = 1;
	info.isTitle = true;
	UIDropDownMenu_AddButton(info);

	info = {}; -- Sets
	info.text = "Sets:";
	info.notCheckable = 1;
	info.isTitle = true;
	UIDropDownMenu_AddButton(info);

	if GetNumEquipmentSets() == 0 then
		info = {}; -- no Equipment sets
		info.text = BEMB_NOSETS;
		info.value = "nosets";
		info.func = BEMB_DropDown_Click;
		info.icon = "Interface\\Icons\\Spell_Holy_ProclaimChampion";
		info.notCheckable = 1;
		info.notClickable = 1;
		UIDropDownMenu_AddButton(info);
	else
		for i=1, GetNumEquipmentSets() do
			local name, icon, _ = GetEquipmentSetInfo(i);
			info = {}; -- equipment set buttons
			info.text = name;
			info.value = "equipset "..i;
			info.func = BEMB_DropDown_Click;
			info.icon = icon;
			info.notCheckable = 1;
			UIDropDownMenu_AddButton(info);
		end;
	end;

	info = {}; -- Empty Space
	info.text = " ";
	info.notCheckable = 1;
	info.notClickable = 1;
	UIDropDownMenu_AddButton(info);

--	if ( GetCVarBool("equipmentManager") ) then
		info = {}; -- show equipment manager
		info.text = BEMB_SHOW;
		info.value = "showgm";
		info.notCheckable = 1;
		info.func = BEMB_DropDown_Click;
		UIDropDownMenu_AddButton(info);
--[[	else
		info = {}; --enable equipment manager
		info.text = BEMB_ENABLE;
		info.value = "enablegm";
		info.notCheckable = 1;
		info.func = BEMB_DropDown_Click;
		UIDropDownMenu_AddButton(info);
	end; ]]
	
	info = {} -- information button
	info.text = BEMB_INFO;
	info.value = "info";
	info.notCheckable = 1;
	info.func = BEMB_DropDown_Click;
	UIDropDownMenu_AddButton(info);

	info = {}; -- close button
	info.text = BEMB_CLOSE;
	info.value = "close";
	info.func = BEMB_DropDown:Hide();
	info.notCheckable = 1
	UIDropDownMenu_AddButton(info);

	info = nil; -- clear table
end;


if not BEMBDB then
	BEMBDB = {
		MinimapPos = 180 -- default position of the minimap icon in degrees
	}
end;