--[[
	Banknon 
		Combines the player's bank into a single frame
--]]

--[[ 
	Loading Functions
--]]

function Banknon_OnLoad()
	this:RegisterEvent("ADDON_LOADED");
end

--[[
	Event Handler
--]]

function Banknon_OnEvent(event)
	if ( event == "BANKFRAME_OPENED" ) then
		bgn_atBank = 1;
		BagnonCore_GenerateFrame(Banknon);
	elseif( event == "BANKFRAME_CLOSED" ) then
		bgn_atBank = nil;
		Banknon:Hide();
	elseif ( event == "ADDON_LOADED" and arg1 == "Banknon") then
		this:UnregisterEvent("ADDON_LOADED");
		Banknon_Load();
	end
end

function Banknon_Load()
	BagnonCore_LoadSettings(Banknon, {-1, 5, 6, 7, 8, 9, 10}, 192, "Bank");
	
	if(CT_BankFrame_AcceptFrame) then
		CT_BankFrame_AcceptFrame:SetParent(Banknon);
	else
		BankBuy_OnLoad();
	end

	Banknon:RegisterEvent("BANKFRAME_CLOSED");
	Banknon:RegisterEvent("BANKFRAME_OPENED");
	
	Banknon_UpdateSlotCost();
end

--[[
	UI Functions
--]]

--OnShow
function Banknon_OnShow()
	PlaySound("igMainMenuOpen");
end

--OnHide
function Banknon_OnHide()
	PlaySound("igMainMenuClose");
	CloseBankFrame();
end

--[[
	Bank Slots functions
--]]


--[[ Show/Hide the bag frame ]]--

function Banknon_ToggleSlots()
	if( not BanknonBags:IsShown() ) then
		BanknonBags:Show();
		this:SetText("Hide Bags");
	else
		BanknonBags:Hide();
		this:SetText("Show Bags");
	end
	
	BagnonCore_TrimToSize(Banknon);
end

function Banknon_UpdateSlotCost()
	local numSlots, full = GetNumBankSlots();
	
	if( full ) then
		BanknonBagsPurchase:Hide();
		BanknonBagsCost:Hide();
	else
		BanknonBagsPurchase:Show();
		BanknonBagsCost:Show();
		
		local cost = GetBankSlotCost(numSlots);
		if( GetMoney() >= cost ) then
			SetMoneyFrameColor("BanknonBagsCost", 1.0, 1.0, 1.0);
		else
			SetMoneyFrameColor("BanknonBagsCost", 1.0, 0.1, 0.1)
		end
		MoneyFrame_Update("BanknonBagsCost", cost);
	end
end