---------
---
--- GoldCounter (Options.lua) by Hexiatröhm
---
---------
local format = string.format
local gsub   = string.gsub
local floor  = math.floor
local abs    = math.abs
local sub	 = string.sub
local find   = string.find
local lower  = string.lower
local len 	 = string.len
local upper  = string.upper

local i, _ = nil, nil

--- Custom Icons
GC_FactionIconAlliance 	= "Interface\\AddOns\\GoldCounter\\Icons\\Icon_Alliance_Small.tga"
GC_FactionIconHorde 	= "Interface\\AddOns\\GoldCounter\\Icons\\Icon_Horde_Small.tga"
GC_FactionIconNeutral 	= "Interface\\AddOns\\GoldCounter\\Icons\\Icon_Neutral_Big.tga"
GC_FactionIconAllianceART = "Interface\\AddOns\\GoldCounter\\Icons\\Icon_Alliance_Big.tga"
GC_FactionIconHordeART 	  = "Interface\\AddOns\\GoldCounter\\Icons\\Icon_Horde_Big.tga"
GC_FactionIconNeutralART  = "Interface\\AddOns\\GoldCounter\\Icons\\Icon_Neutral_Big.tga"

GC_Mouse_LeftClickIcon   = "Interface\\AddOns\\GoldCounter\\Icons\\MouseLeft.tga"
GC_Mouse_RightClickIcon  = "Interface\\AddOns\\GoldCounter\\Icons\\MouseRight.tga"
GC_Mouse_MiddleClickIcon = "Interface\\AddOns\\GoldCounter\\Icons\\MouseMiddle.tga"
---

----------
function GC_SetAddonOptions()

	-----------------------------
	--- Init Addon Basic Options
	if ( not My_GC_Settings_Local.ShowGoldOnly_SW ) then
		My_GC_Settings_Local.ShowGoldOnly = false
		My_GC_Settings_Local.ShowGoldOnly_SW = true
	end
	if ( not My_GC_Settings_Local.UseShiftToDrag_SW ) then
		My_GC_Settings_Local.UseShiftToDrag = false
		My_GC_Settings_Local.UseShiftToDrag_SW = true
	end
	if ( not My_GC_Settings_Local.DailyReset_SW ) then
		My_GC_Settings_Local.DailyReset = false
		My_GC_Settings_Local.DailyReset_SW = true
	end
	if ( not My_GC_Settings_Local.TransView_SW ) then
		My_GC_Settings_Local.TransView = false
		My_GC_Settings_Local.TransView_SW = true
	end
	if ( not My_GC_Settings_Local.HideInCombat_SW ) then
		My_GC_Settings_Local.HideInCombat = false
		My_GC_Settings_Local.HideInCombat_SW = true
	end
	if ( not My_GC_Settings_Local.MinimapButtonUse_SW ) then
		My_GC_Settings_Local.MinimapButtonUse = true
		My_GC_Settings_Local.MinimapButtonUse_SW = true
	end
	if ( not My_GC_Settings_Local.IconsFlash_SW ) then
		My_GC_Settings_Local.IconsFlash = true
		My_GC_Settings_Local.IconsFlash_SW = true
	end
	if ( not My_GC_Settings_Local.CheckBank_SW ) then
		My_GC_Settings_Local.CheckBank = false
		My_GC_Settings_Local.CheckBank_SW = true
	end
	-----------------------------

	-----------------------------
	--- Init Special Options
	if ( not My_GC_Settings_Local.Scale )         then My_GC_Settings_Local.Scale         = 1
	end
	if ( not My_GC_Settings_Local.Font )          then My_GC_Settings_Local.Font          = GC_CounterFonts_List[1]
	end
	if ( not My_GC_Settings_Local.LastResetDate ) then My_GC_Settings_Local.LastResetDate = tonumber( date("%y%m%d") )
	end
	if ( not My_GC_Settings_Local.Thousand_Delimiter ) then My_GC_Settings_Local.Thousand_Delimiter = ","
	end
	if ( not My_GC_Settings_Local.UserDateFormat ) then My_GC_Settings_Local.UserDateFormat = "YY/MM/DD"
	end
	if not My_GC_Settings_Local.GC_Version then My_GC_Settings_Local.GC_Version = GC_Version
	end
	-----------------------------

	-----------------------------
	--- Init Login time if never recorded
	if not My_GC_Settings_Local.LastLoginDate or not My_GC_Settings_Local.LastLoginTime then
		My_GC_Settings_Local.LastLoginDate = tonumber( date("%y%m%d") )
		My_GC_Settings_Local.LastLoginTime = date("%H:%M:%S")
	end
	-----------------------------

	-----------------------------
	--- Init Logout time if never recorded
	if not My_GC_Settings_Local.LastLogoutDate or not My_GC_Settings_Local.LastLogoutTime then
		My_GC_Settings_Local.LastLogoutDate = tonumber( date("%y%m%d") )
		My_GC_Settings_Local.LastLogoutTime = date("%H:%M:%S")
	end
	-----------------------------

	-----------------------------
	--- Check Reset History Lenght
	if not My_GC_Settings_Local.MaxHistoryRec or My_GC_Settings_Local.MaxHistoryRec < GC_MinHistoryRec then
		My_GC_Settings_Local.MaxHistoryRec = GC_MinHistoryRec
	elseif My_GC_Settings_Local.MaxHistoryRec > GC_MaxHistoryRec then
		My_GC_Settings_Local.MaxHistoryRec = GC_MaxHistoryRec
	end
	--- Set History Lenght in EditBox
	GC_HistListRec_Len:SetNumber( My_GC_Settings_Local.MaxHistoryRec )
	GC_HistListRec_Len:SetCursorPosition(0)
	--- Create or Reset History Table
	GC_BuildHistoryTable()
	-----------------------------

	-----------------------------
	--- Init GC_MyDailyData
	if not GC_MyDailyData.DailyCount then GC_MyDailyData.DailyCount = 0 end
	if not GC_MyDailyData.Instance_MoneyLoot then GC_MyDailyData.Instance_MoneyLoot = 0 end
	if not GC_MyDailyData.Money_Loot then GC_MyDailyData.Money_Loot = 0 end
	if not GC_MyDailyData.Merchant_Money then GC_MyDailyData.Merchant_Money = 0 end
	if not GC_MyDailyData.Auctioneer then GC_MyDailyData.Auctioneer = 0 end
	if not GC_MyDailyData.MailBoxIncome then GC_MyDailyData.MailBoxIncome = 0 end
	if not GC_MyDailyData.QuestReward then GC_MyDailyData.QuestReward = 0 end
	if not GC_MyDailyData.QuestXP then GC_MyDailyData.QuestXP = 0 end
	if not GC_MyDailyData.Merchant_Transmo then GC_MyDailyData.Merchant_Transmo = 0 end
	if not GC_MyDailyData.TaxiCost then GC_MyDailyData.TaxiCost = 0 end
	-----------------------------

	-----------------------------
	--- Set up Addon and Options Panel UI and texts
	
	--- Frame Scaling and Slider Position
		GC_Options_ScalingSlider:SetValue( My_GC_Settings_Local.Scale )
		GC_Scale_CurrentValue:SetText( My_GC_Settings_Local.Scale ) --- Set Value number
		GoldCounter_MainFrame:SetScale( My_GC_Settings_Local.Scale ) --- Set Frame Scale
	--- Frame Mode or Tranlucent Mode
		GC_Options_CheckButton1:SetChecked( My_GC_Settings_Local.TransView ) --- Check or uncheck button
		GC_ChangeViewMode( My_GC_Settings_Local.TransView )
		GC_ResetFrame() --- Reset Frame basic color if Shown
	--- Only Showing Gold setting
		GC_Options_CheckButton2:SetChecked( My_GC_Settings_Local.ShowGoldOnly ) --- Check or uncheck button
		GC_ShowOnlyGold( My_GC_Settings_Local.ShowGoldOnly )
	--- Use Shift To Drag Option
		GC_Options_CheckButton3:SetChecked( My_GC_Settings_Local.UseShiftToDrag ) --- Check or uncheck button
	--- Daily Reset Set button
		GC_Options_CheckButton4:SetChecked( My_GC_Settings_Local.DailyReset ) --- Check or uncheck button
	--- Hide In Combat Set button
		GC_Options_CheckButton5:SetChecked( My_GC_Settings_Local.HideInCombat ) --- Check or uncheck button
	--- Set Button for Bank Check
		GC_Options_CheckBank:SetChecked( My_GC_Settings_Local.CheckBank ) --- Check or uncheck button
	--- Set Button for Lights Effects
		GC_Options_ButtonsFlash:SetChecked( My_GC_Settings_Local.IconsFlash) --- Check or uncheck button
	-----------------------------

	-----------------------------
	--- Minimap Button Hide or Show
		GC_Options_MinimapButton:SetChecked( My_GC_Settings_Local.MinimapButtonUse ) --- Check or uncheck button
		--- Minimap Button Hide or Show
		if ( My_GC_Settings_Local.MinimapButtonUse == false ) then
			GC_Icon:Hide("GOLDCOUNTER")
		else
			GC_Icon:Show("GOLDCOUNTER")
		end
	-----------------------------

	-----------------------------
	--- Lights Effects will Stop/Start if allowed
		if ( My_GC_Settings_Local.IconsFlash == false ) then

			StopLoop1()
			StopLoop2()
		else --- Testing if at login is resting or fighting
			GC_CheckResting()
			GC_CheckFighting()
		end
	-----------------------------

	-----------------------------
	--- Set Profile Names on option panel
	for i = 1, 6, 1 do
		if ( My_GC_Profile[i] ) then

			local name = GC_GetClassColor( My_GC_Profile[i].Name, My_GC_Profile[i].Class )
			_G["GC_Profile"..i.."_ButtonDefText"]:SetText( name )

		else
			_G["GC_Profile"..i.."_ButtonDefText"]:SetText( GC_Locale_Text.OPTIONSPANEL_PROFILE_TEXT.." "..i )
		end
	end

end
	-----------------------------

function XML_Actions( Option )

	if not Option or Option == 0 then return end

	--- 1  = Frame Right-Click Menu

	if Option == 1 then

		--- Frame Right-Click Menu
		GCLibDD:ToggleDropDownMenu(1, nil, GC_OptionsMenuFrame, "cursor", 3, -3)
		PlaySound( SOUNDKIT.IG_MAINMENU_OPTION )

	elseif Option == 2 then
		--- Undefined
	end

end
----------
function GC_ChangeViewMode( switch )

	if switch == true then --- Transparent

		StopLoop1() --- Stop All Anim
		StopLoop2()

		GoldCounter_MainFrame:SetBackdrop( {
                    bgFile = "",
                    edgeFile = "",
                    tile = true,
                    tileSize = 16,
                    edgeSize = 16,
                    insets = { left=2, right=2, top=2, bottom=2 } } )

                GoldCounter_MainFrame:SetBackdropColor(0,0,0,0)
                GoldCounter_MainFrame:SetBackdropBorderColor(0,0,0,0)

		GC_InfosGearButton:SetPoint( "LEFT", "GoldCounter_MainFrame", "RIGHT", "-8", "0" )

	else --- Non Transparent

		GC_ResetFrame()

		GC_InfosGearButton:SetPoint( "LEFT", "GoldCounter_MainFrame", "LEFT", "1", "0" )
		GoldCounter_MainFrame:SetClampedToScreen( true )

		GC_CheckResting()
		GC_CheckFighting()

	end

end

function GC_ShowOnlyGold( switch )

	if ( switch == true ) then

		GC_CopperButton:Hide()
		GC_ShowCoppers:Hide()

		GC_SilverButton:Hide()
		GC_ShowSilvers:Hide()

		GC_GoldButton:SetPoint( "RIGHT", "GC_CopperButton", "LEFT", "14", "0" )

	else
		GC_CopperButton:Show()
		GC_ShowCoppers:Show()

		GC_SilverButton:Show()
		GC_ShowSilvers:Show()

		GC_GoldButton:SetPoint( "RIGHT", "GC_SilverButton", "LEFT", "-24", "0" )

	end

end

------------------
function GC_GetClassColor( Name, Class )

	if ( Class == "WARRIOR" ) then         Name = "|cffC69B6D"..Name.."|r"
	elseif ( Class == "WARLOCK" ) then     Name = "|cff8788EE"..Name.."|r"
	elseif ( Class == "SHAMAN" ) then      Name = "|cff0070DD"..Name.."|r"
	elseif ( Class == "ROGUE" ) then       Name = "|cffFFF468"..Name.."|r"
	elseif ( Class == "PRIEST" ) then      Name = "|cffFFFFFF"..Name.."|r"
	elseif ( Class == "PALADIN" ) then     Name = "|cffF48CBA"..Name.."|r"
	elseif ( Class == "MONK" ) then        Name = "|cff00FF98"..Name.."|r"
	elseif ( Class == "MAGE" ) then        Name = "|cff3FC7EB"..Name.."|r"
	elseif ( Class == "HUNTER" ) then      Name = "|cffAAD372"..Name.."|r"
	elseif ( Class == "EVOKER" ) then      Name = "|cff33937F"..Name.."|r"
	elseif ( Class == "DRUID" ) then       Name = "|cffFF7C0A"..Name.."|r"
	elseif ( Class == "DEMONHUNTER" ) then Name = "|cffA330C9"..Name.."|r"
	elseif ( Class == "DEATHKNIGHT" ) then Name = "|cffC41E3A"..Name.."|r"
	end

	return Name
end
------------------
function GC_CheckNewVersion( OldVer, NewVer ) --- return nil if same or lower version

	if ( not NewVer ) then return nil end

	local VerMaj1, VerMin1, VerSubMin1 = strsplit( ".", OldVer, 3 )
	VerMaj1, VerMin1, VerSubMin1 = tonumber(VerMaj1), tonumber(VerMin1), tonumber(VerSubMin1)

	local VerMaj2, VerMin2, VerSubMin2 = strsplit( ".", NewVer, 3 )
	VerMaj2, VerMin2, VerSubMin2 = tonumber(VerMaj2), tonumber(VerMin2), tonumber(VerSubMin2)

	local Version

	if VerMaj1 < VerMaj2 then
	Version = true

	elseif VerMaj1 == VerMaj2 and VerMin1 < VerMin2 then
	Version = true
	
	elseif VerMaj1 == VerMaj2 and VerMin1 == VerMin2 and VerSubMin1 < VerSubMin2 then
	Version = true

	else

		Version = nil

	end

	return Version
end

function GC_OptionsMenuFrame_OnClick( self, arg1, arg2, checked )

	if ( arg1 == 2 ) then

		My_GC_Settings_Local.TransView = checked

	elseif ( arg1 == 3 ) then

		My_GC_Settings_Local.ShowGoldOnly = checked

	elseif ( arg1 == 4 ) then

		My_GC_Settings_Local.UseShiftToDrag = checked

	elseif ( arg1 == 5 ) then

		My_GC_Settings_Local.HideInCombat = checked

	elseif ( arg1 == 7 ) then

		GoldCounterOptionsPanel:Show()

	elseif ( arg1 > 7 ) then

		GC_LoadProfile( arg1 - 7 )
		GCLibDD:ToggleDropDownMenu(1, nil, GC_OptionsMenuFrame )
	end

	GC_SetAddonOptions()

end

function GC_ShowCharFunds( Frame )
 
		GC_CurrentFunds = GetMoney()
		
		local TotalFunds = GC_CurrentFunds
		local TotalFundsExt = 0
		local ColoredName, TextureString = "", ""
		local CurrentGold, Funds, FontsIndex, OverallGold, ScanIndex, ScanIndexExt = 0,"",0,0,0,0
		local MyBandSavedMoney = { 0, nil }
		local WarbandBankFormatted = " "
		
			--- Check WarBandBank
			if ( GC_WOW_isRetail == true ) then --- Warband bank only in Retail

			MyBandSavedMoney[1] = C_Bank.FetchDepositedMoney(Enum.BankType.Account) or 0
			MyBandSavedMoney[2] = GetMoneyString(C_Bank.FetchDepositedMoney(Enum.BankType.Account), true) --- Seen in the code example - Unused

				WarbandBankFormatted = GC_MoneyCoinsTextures( nil, MyBandSavedMoney[1], false )

			end
			------

			--- Get Initial ItemLevel
			GC_PlayerItemLevel = GC_GetPlayerItemLevel()

		--- Tooltip 1
		--- Current Character Money

		GoldCounter_Custom_Tooltip:SetOwner( Frame , "ANCHOR_BOTTOM" )
		GoldCounter_Custom_Tooltip:ClearLines()

		GoldCounter_Custom_TooltipTextLeft1:SetFontObject( Fancy12Font ) --- Title
		GoldCounter_Custom_Tooltip:AddLine( GC_Locale_Text.TOOLTIP_INFOS_FUNDS, nil, nil, nil, false )

		GoldCounter_Custom_TooltipTextLeft2:SetFontObject( Fancy12Font )
		GoldCounter_Custom_Tooltip:AddLine( " ", 0, 0, 0, false )

		---------
		ColoredName = GC_GetClassColor( GC_PlayerName, GC_PlayerClass )
		Funds = GC_MoneyCoinsTextures( nil, TotalFunds, true )

		GoldCounter_Custom_TooltipTextLeft3:SetFontObject( "SystemFont_Small" )
		GoldCounter_Custom_TooltipTextRight3:SetFont("Interface\\AddOns\\GoldCounter\\Fonts\\JetBrainsMonoNL-SemiBold.ttf", 10, "") --- Current Player Money
		GoldCounter_Custom_Tooltip:AddDoubleLine( ColoredName.." |cffffff00(|r".. UnitLevel( "player" ) .."|cffffff00)|r "..
		"|cff00ffff[|r".. "|cff909090" .. GC_PlayerItemLevel .."|r|cff00ffff]|r",
		GC_MyMoney.NoColor..Funds.."|r", 1, 1, 1 )

		---

		--- Add Faction Icon
		if GC_PlayerFaction == "Alliance" then

			GoldCounter_Custom_Tooltip:AddTexture( GC_FactionIconAlliance ,
				{ width = 10, height = 12, margin = { left = 0, right = 3, top = 0, bottom = 0 } } )

		elseif GC_PlayerFaction == "Horde" then

			GoldCounter_Custom_Tooltip:AddTexture( GC_FactionIconHorde ,
				{ width = 10, height = 12, margin = { left = 0, right = 3, top = 0, bottom = 0 } } )

		else

			GoldCounter_Custom_Tooltip:AddTexture( GC_FactionIconNeutral ,
				{ width = 10, height = 12, margin = { left = 0, right = 3, top = 0, bottom = 0 } } )

		end
		---

		GoldCounter_Custom_TooltipTextLeft4:SetFontObject("GameFontWhiteTiny")
		GoldCounter_Custom_Tooltip:AddLine( "_____________________________________________________________", 0.7, 0.7, 0.7, false )

		GoldCounter_Custom_TooltipTextLeft5:SetFontObject("GameFontWhiteTiny")
		GoldCounter_Custom_Tooltip:AddLine( " ", 0, 0, 0, false )


		------------------------------
		------ Other Characters ------

		--- Scan how many chars
		ScanIndex = 0
		ScanIndexExt = 0
		FontsIndex = 5

		for i = 1, #My_GC_CharMoneyDB do

			--- Count how many chars in current server
			if ( My_GC_CharMoneyDB[i].Realm == GC_PlayerRealm ) then

				ScanIndex = ScanIndex + 1

			--- Count how many chars in other server in Retail
			elseif GC_WOW_isRetail == true then

				ScanIndexExt = ScanIndexExt + 1
			end

		end

		if ( ScanIndex == 1 and ScanIndexExt == 0 ) then --- If only current logged char and no other in account

			--- Warband account money - Retail only
			if ( GC_WOW_isRetail == true and MyBandSavedMoney and MyBandSavedMoney[1] > 0 ) then --- Warband bank amount only in Retail

			FontsIndex = FontsIndex + 1
			_G["GoldCounter_Custom_TooltipTextLeft"..FontsIndex]:SetFontObject("GameFontWhiteTiny")
			_G["GoldCounter_Custom_TooltipTextRight"..FontsIndex]:SetFontObject("FriendsFont_Small")
			GoldCounter_Custom_Tooltip:AddDoubleLine( GC_Locale_Text.TOOLTIP_WARBAND_BANK, WarbandBankFormatted, 1, 1, 1 )

			TotalFunds = TotalFunds + MyBandSavedMoney[1]

			end

			FontsIndex = FontsIndex + 1
			_G["GoldCounter_Custom_TooltipTextLeft"..FontsIndex]:SetFontObject("GameFontWhiteTiny")
			_G["GoldCounter_Custom_TooltipTextRight"..FontsIndex]:SetFontObject("FriendsFont_Small")

			TextureString = GC_MoneyCoinsTextures( nil, TotalFunds, true )
			GoldCounter_Custom_Tooltip:AddDoubleLine( GC_Locale_Text.TOOLTIP_INFOS_TOTAL, TextureString, nil, nil, nil, false )

			FontsIndex = FontsIndex + 1
			_G["GoldCounter_Custom_TooltipTextLeft"..FontsIndex]:SetFontObject("GameFontWhiteTiny")
			GoldCounter_Custom_Tooltip:AddLine( " ", 0, 0, 0, false )

			FontsIndex = FontsIndex + 1
			_G["GoldCounter_Custom_TooltipTextLeft"..FontsIndex]:SetFontObject("GameFontWhiteTiny")
			GoldCounter_Custom_Tooltip:AddLine( GC_Locale_Text.TOOLTIP_INFOS_NODATA, 0.4, 0.4, 0.4, false )

			return

		else

			--- Same Server
			for i = 1, #My_GC_CharMoneyDB do

				--- Retail
				if ( GC_WOW_isRetail == true and My_GC_CharMoneyDB[i].NormName ~= GC_PlayerNormName and 
						My_GC_CharMoneyDB[i].Realm == GC_PlayerRealm ) then

					ColoredName = GC_GetClassColor( My_GC_CharMoneyDB[i].Name, My_GC_CharMoneyDB[i].Class )

					Funds = GC_MoneyCoinsTextures( nil, My_GC_CharMoneyDB[i].Funds, true )


					TotalFunds = TotalFunds + My_GC_CharMoneyDB[i].Funds

					FontsIndex = FontsIndex + 1
					
					--- Numbers for Characters List
					if not My_GC_CharMoneyDB[i].ItemLevel then My_GC_CharMoneyDB[i].ItemLevel = "?" end
					_G["GoldCounter_Custom_TooltipTextLeft"..FontsIndex]:SetFontObject( "SystemFont_Small" )
					_G["GoldCounter_Custom_TooltipTextRight"..FontsIndex]:SetFont("Interface\\AddOns\\GoldCounter\\Fonts\\JetBrainsMonoNL-SemiBold.ttf", 10, "")
					GoldCounter_Custom_Tooltip:AddDoubleLine( ColoredName.." |cffffff00(|r".. My_GC_CharMoneyDB[i].Level .."|cffffff00)|r "..
					"|cff00ffff[|r".. "|cff909090" .. My_GC_CharMoneyDB[i].ItemLevel .."|r|cff00ffff]|r",
					GC_MyMoney.NoColor..Funds.."|r", 1, 1, 1 )

					--- Add Faction Icon
					if My_GC_CharMoneyDB[i].Faction == "Alliance" then

						GoldCounter_Custom_Tooltip:AddTexture( GC_FactionIconAlliance,
							{ width = 10, height = 12, margin = { left = 0, right = 3, top = 0, bottom = 0 } } )

					elseif My_GC_CharMoneyDB[i].Faction == "Horde" then

						GoldCounter_Custom_Tooltip:AddTexture( GC_FactionIconHorde,
							{ width = 10, height = 12, margin = { left = 0, right = 3, top = 0, bottom = 0 } } )
					else

						GoldCounter_Custom_Tooltip:AddTexture( GC_FactionIconNeutral,
							{ width = 10, height = 12, margin = { left = 0, right = 3, top = 0, bottom = 0 } } )
					end

				--- Classic
				elseif My_GC_CharMoneyDB[i].NormName ~= GC_PlayerNormName and My_GC_CharMoneyDB[i].Realm == GC_PlayerRealm
					and My_GC_CharMoneyDB[i].Faction == GC_PlayerFaction then


					ColoredName = GC_GetClassColor( My_GC_CharMoneyDB[i].Name, My_GC_CharMoneyDB[i].Class )

					Funds = GC_MoneyCoinsTextures( nil, My_GC_CharMoneyDB[i].Funds, true )

					TotalFunds = TotalFunds + My_GC_CharMoneyDB[i].Funds
					FontsIndex = FontsIndex + 1

					if not My_GC_CharMoneyDB[i].ItemLevel then My_GC_CharMoneyDB[i].ItemLevel = "?" end
					_G["GoldCounter_Custom_TooltipTextLeft"..FontsIndex]:SetFontObject( "SystemFont_Small")
					_G["GoldCounter_Custom_TooltipTextRight"..FontsIndex]:SetFont("Interface\\AddOns\\GoldCounter\\Fonts\\JetBrainsMonoNL-SemiBold.ttf", 10, "")
					GoldCounter_Custom_Tooltip:AddDoubleLine( ColoredName.." |cffffff00(|r".. My_GC_CharMoneyDB[i].Level .."|cffffff00)|r "..
					"|cff00ffff[|r".. "|cff909090" .. My_GC_CharMoneyDB[i].ItemLevel .."|r|cff00ffff]|r",
					GC_MyMoney.NoColor..Funds.."|r", 1, 1, 1 )

						--- Add Faction Icon
						if My_GC_CharMoneyDB[i].Faction == "Alliance" then

							GoldCounter_Custom_Tooltip:AddTexture( GC_FactionIconAlliance ,
								{ width = 10, height = 12, margin = { left = 0, right = 3, top = 0, bottom = 0 } } )

						elseif My_GC_CharMoneyDB[i].Faction == "Horde" then

							GoldCounter_Custom_Tooltip:AddTexture( GC_FactionIconHorde ,
								{ width = 10, height = 12, margin = { left = 0, right = 3, top = 0, bottom = 0 } } )

						else

							GoldCounter_Custom_Tooltip:AddTexture( GC_FactionIconNeutral ,
								{ width = 10, height = 12, margin = { left = 0, right = 3, top = 0, bottom = 0 } } )

						end

				end

			end

			--- Space if more than 1 character
			if ( ScanIndex > 1 ) then
				FontsIndex = FontsIndex + 1
				_G["GoldCounter_Custom_TooltipTextLeft"..FontsIndex]:SetFontObject("GameFontWhiteTiny")
				GoldCounter_Custom_Tooltip:AddLine( "_____________________________________________________________", 0.7, 0.7, 0.7, false )

			FontsIndex = FontsIndex + 1
			_G["GoldCounter_Custom_TooltipTextLeft"..FontsIndex]:SetFontObject("GameFontWhiteTiny")
			GoldCounter_Custom_Tooltip:AddLine( " ", 0, 0, 0, false )
			end

			--- Warband account money - Retail only
			if ( GC_WOW_isRetail == true and MyBandSavedMoney and MyBandSavedMoney[1] > 0 ) then --- Warband bank amount only in Retail

			FontsIndex = FontsIndex + 1
			_G["GoldCounter_Custom_TooltipTextLeft"..FontsIndex]:SetFontObject("GameFontWhiteTiny")
			_G["GoldCounter_Custom_TooltipTextRight"..FontsIndex]:SetFontObject("FriendsFont_Small")
			GoldCounter_Custom_Tooltip:AddDoubleLine( GC_Locale_Text.TOOLTIP_WARBAND_BANK, WarbandBankFormatted, 1, 1, 1 )

			TotalFunds = TotalFunds + MyBandSavedMoney[1]

			end


			--- Total Funds
			FontsIndex = FontsIndex + 1

			_G["GoldCounter_Custom_TooltipTextLeft"..FontsIndex]:SetFontObject("GameFontWhiteTiny")
			_G["GoldCounter_Custom_TooltipTextRight"..FontsIndex]:SetFontObject("FriendsFont_Small")

			TextureString = GC_MoneyCoinsTextures( nil, TotalFunds, true )

			GoldCounter_Custom_Tooltip:AddDoubleLine( GC_Locale_Text.TOOLTIP_INFOS_TOTAL, TextureString, nil, nil, nil )

		end


		--- Other Server - Retail only
		if ( GC_WOW_isRetail == true and ScanIndexExt > 0 ) then

			--- Space
			FontsIndex = FontsIndex + 1
			_G["GoldCounter_Custom_TooltipTextLeft"..FontsIndex]:SetFontObject("GameFontWhiteTiny")
			GoldCounter_Custom_Tooltip:AddLine( "_____________________________________________________________", 0.7, 0.7, 0.7, false )
			FontsIndex = FontsIndex + 1
			_G["GoldCounter_Custom_TooltipTextLeft"..FontsIndex]:SetFontObject("GameFontWhiteTiny")
			GoldCounter_Custom_Tooltip:AddLine( " ", 0, 0, 0, false )

			for i = 1, #My_GC_CharMoneyDB do

				if ( GC_WOW_isRetail == true and My_GC_CharMoneyDB[i].Realm ~= GC_PlayerRealm ) then

				ColoredName = GC_GetClassColor( My_GC_CharMoneyDB[i].NormName, My_GC_CharMoneyDB[i].Class )

				TotalFundsExt = TotalFundsExt + My_GC_CharMoneyDB[i].Funds
				FontsIndex = FontsIndex + 1


				Funds = GC_MoneyCoinsTextures( nil, My_GC_CharMoneyDB[i].Funds, true )

				if not My_GC_CharMoneyDB[i].ItemLevel then My_GC_CharMoneyDB[i].ItemLevel = "?" end
				_G["GoldCounter_Custom_TooltipTextLeft"..FontsIndex]:SetFontObject( "SystemFont_Small" )
				_G["GoldCounter_Custom_TooltipTextRight"..FontsIndex]:SetFont("Interface\\AddOns\\GoldCounter\\Fonts\\JetBrainsMonoNL-SemiBold.ttf", 10, "")
				GoldCounter_Custom_Tooltip:AddDoubleLine( ColoredName.." |cffffff00(|r".. My_GC_CharMoneyDB[i].Level .."|cffffff00)|r "..
				"|cff00ffff[|r".. "|cff909090" .. My_GC_CharMoneyDB[i].ItemLevel .."|r|cff00ffff]|r",
				GC_MyMoney.NoColor..Funds.."|r", 1, 1, 1 )

				--- Add Faction Icon
				if My_GC_CharMoneyDB[i].Faction == "Alliance" then

					GoldCounter_Custom_Tooltip:AddTexture( GC_FactionIconAlliance ,
						{ width = 10, height = 12, margin = { left = 0, right = 3, top = 0, bottom = 0 } } )

				elseif My_GC_CharMoneyDB[i].Faction == "Horde" then

					GoldCounter_Custom_Tooltip:AddTexture( GC_FactionIconHorde ,
						{ width = 10, height = 12, margin = { left = 0, right = 3, top = 0, bottom = 0 } } )

				else

					GoldCounter_Custom_Tooltip:AddTexture( GC_FactionIconNeutral ,
						{ width = 10, height = 12, margin = { left = 0, right = 3, top = 0, bottom = 0 } } )
				end

				end
			end

			--- Space
			FontsIndex = FontsIndex + 1
			_G["GoldCounter_Custom_TooltipTextLeft"..FontsIndex]:SetFontObject("GameFontWhiteTiny")
			GoldCounter_Custom_Tooltip:AddLine( "_____________________________________________________________", 0.7, 0.7, 0.7, false )
			FontsIndex = FontsIndex + 1
			_G["GoldCounter_Custom_TooltipTextLeft"..FontsIndex]:SetFontObject("GameFontWhiteTiny")
			GoldCounter_Custom_Tooltip:AddLine( " ", 0, 0, 0, false )


			--- Total Funds
			FontsIndex = FontsIndex + 1

			_G["GoldCounter_Custom_TooltipTextLeft"..FontsIndex]:SetFontObject("GameFontWhiteTiny")
			_G["GoldCounter_Custom_TooltipTextRight"..FontsIndex]:SetFontObject("FriendsFont_Small")

			TextureString = GC_MoneyCoinsTextures( nil, TotalFundsExt, true )

			GoldCounter_Custom_Tooltip:AddDoubleLine( GC_Locale_Text.TOOLTIP_INFOS_TOTAL, TextureString, nil, nil, nil )

			--- Total Account Funds
			FontsIndex = FontsIndex + 1
			local AccountFunds = TotalFunds + TotalFundsExt

			TextureString = GC_MoneyCoinsTextures( nil, AccountFunds, true )

			_G["GoldCounter_Custom_TooltipTextLeft"..FontsIndex]:SetFontObject( GameFontWhiteTiny )
			_G["GoldCounter_Custom_TooltipTextRight"..FontsIndex]:SetFontObject( FriendsFont_Small )
			GoldCounter_Custom_Tooltip:AddDoubleLine( "=", "( "..GC_MyMoney.NoColor..TextureString.."|r )", nil, nil, nil, false )

		end
end

function GC_SetOptionsPanelText()

		GC_Option_ScaleText:SetText( GC_Locale_Text.OPTIONSPANELTXT_SCALE )
		GC_Option_FontText:SetText( GC_Locale_Text.OPTIONSPANELTXT_FONT )

		GC_Options_CheckButton1DefText:SetText( GC_Locale_Text.OPTIONSPANELTXT_TRANSVIEW )
		GC_Options_CheckButton2DefText:SetText( GC_Locale_Text.OPTIONSPANELTXT_SHOWONLYGOLD )
		GC_Options_CheckButton3DefText:SetText( GC_Locale_Text.OPTIONSPANELTXT_USESHIFTDRAG )
		GC_Options_CheckButton4DefText:SetText( GC_Locale_Text.OPTIONSPANELTXT_DAILYRESET )
		GC_Options_CheckButton5DefText:SetText( GC_Locale_Text.OPTIONSPANELTXT_HIDEINCOMBAT )

		GC_Option_HistoryText:SetText( GC_Locale_Text.OPTIONSPANELTXT_HISTORY )

		GC_Options_MinimapButtonDefText:SetText( GC_Locale_Text.OPTIONSPANELTXT_MINIBUTTON )
		GC_Options_ButtonsFlashDefText:SetText( GC_Locale_Text.OPTIONSPANELTXT_FLASHICONS )
		GC_Options_CheckBankDefText:SetText( GC_Locale_Text.OPTIONSPANELTXT_CHECKBANK )

		GC_Options_ClearHistoryButton:SetText( GC_Locale_Text.OPTIONSPANEL_BUTTON1_TEXT )
		GC_Option_ClearDatabaseText:SetText( GC_Locale_Text.OPTIONSPANELTXT_CLEARDB )
		GC_Options_ClearDB_Button:SetText( GC_Locale_Text.OPTIONSPANEL_BUTTON1_TEXT )

		GC_HistListRec_LenDefText:SetText( GC_Locale_Text.OPTIONSPANELTXT_HISTLEN )
		GC_HistListRec_LenDefText2:SetText( "( " .. GC_MinHistoryRec .." - ".. GC_MaxHistoryRec .. " )" )
		
		GC_Option_ThouSeparatorText:SetText( GC_Locale_Text.OPTIONSPANELTXT_THOUSEPARATOR )
		GC_Option_DateFormatText:SetText( GC_Locale_Text.OPTIONSPANELTXT_DATEFORMAT )

		GC_Option_ProfileText:SetText( GC_Locale_Text.OPTIONSPANELTXT_PROFILE )
		GC_Options_ProfileSave_Button:SetText( GC_Locale_Text.OPTIONSPANEL_BUTTON2_TEXT )
		GC_Options_ProfileLoad_Button:SetText( GC_Locale_Text.OPTIONSPANEL_BUTTON3_TEXT )
		GC_Options_ProfileDelete_Button:SetText( GC_Locale_Text.OPTIONSPANEL_BUTTON1_TEXT )

		GC_Options_CloseButton1:SetText( GC_Locale_Text.OPTIONSMENU_CLOSE )
		GC_Options_ResetDefaultsButton1:SetText( GC_Locale_Text.OPTIONSMENU_RESET )

		GC_WarnDialogCancelButton:SetText( GC_Locale_Text.OPTIONSPANEL_BUTTON4_TEXT )
		GC_Warn_DialogText:SetText( GC_Locale_Text.DIALOG_WARNING_DEFAULTS )
		GC_Reset_EraseAllData_Text:SetText( GC_Locale_Text.INIT_ADDON_RESETDATA )
		GC_Reset_EraseAllProfiles_Text:SetText( GC_Locale_Text.INIT_ADDON_RESETPROFILES	 )
end

function GC_CheckHistLen( num, UpOrDown )

	if UpOrDown == 0 then
	
		if num > GC_MaxHistoryRec then
			num = GC_MaxHistoryRec
		elseif num < GC_MinHistoryRec then
			num = GC_MinHistoryRec
		end

		My_GC_Settings_Local.MaxHistoryRec = num
		GC_BuildHistoryTable()

	else
	
		if UpOrDown == 1 then num = num + 1
		elseif UpOrDown == -1 then num = num - 1
		end

		if num > GC_MaxHistoryRec then
			num = GC_MinHistoryRec
		elseif num < GC_MinHistoryRec then
			num = GC_MaxHistoryRec
		end
	
	end

	return num
end

function GC_BuildHistoryTable()

	local HistSize		= #MySavedMoneyHistory
	local MaxSize 		= My_GC_Settings_Local.MaxHistoryRec

	------------------------
	-- If new table then Build it or reset
	if HistSize == 0 or not MySavedMoneyHistory[1].date then

		for i = 1, MaxSize, 1 do
			MySavedMoneyHistory[i] = { }
			MySavedMoneyHistory[i].date = "*"
			MySavedMoneyHistory[i].amount = "*"
			MySavedMoneyHistory[i].sign = "*"
		end

	-- Increase to new MaxSize
	elseif HistSize < MaxSize then
	
		for i = HistSize+1, MaxSize, 1 do
			MySavedMoneyHistory[i] = { }
			MySavedMoneyHistory[i].date = "*"
			MySavedMoneyHistory[i].amount = "*"
			MySavedMoneyHistory[i].sign = "*"
		end
	
	-- Decrease to new MaxSize
	elseif HistSize > MaxSize then
	
		for i = HistSize, MaxSize+1, -1 do
			MySavedMoneyHistory[i] = nil
		end

	end

	-- Cleaning rest of the table
	for i = MaxSize+1, 99, 1 do
		MySavedMoneyHistory[i] = nil
	end
	------------------------
end
function GC_ClearHistory()

    MySavedMoneyHistory = { }
	GC_BuildHistoryTable()
	GC_MyDailyData.DailyCount = 0

	DEFAULT_CHAT_FRAME:AddMessage( "|cffffff00GoldCounter|r "..GC_Locale_Text.CHAT_HISTORY_ERASED )
	GC_PlaySFX( 3 )
	
end

function GC_CheckResting()

	local FrameBackdrop = GoldCounter_MainFrame:GetBackdrop()

	--- Border Color
	if IsResting() then --- Si en repos et Frame visible

		if My_GC_Settings_Local.IconsFlash == true 		--- Options animations activée
		and GoldCounter_MainFrame:IsShown() 			--- La frame n'est pas cachée
		and My_GC_Settings_Local.TransView == false		--- Mode non transparent 
		and GC_ToggleSwitch == false					--- Non cachée manuellement
		and FrameBackdrop.bgFile						--- La frame est activée
		and not UnitAffectingCombat("player") then		--- Hors Combat

		StartLoop2() --- Start Blue color border animation
		end

	else

		--- Stop Animation
		StopLoop2()
	end

end

function GC_CheckFighting()

	local FrameBackdrop = GoldCounter_MainFrame:GetBackdrop()

	--- Border Color
	if UnitAffectingCombat("player") then --- Si en combat

		if My_GC_Settings_Local.IconsFlash == true 		--- Options animations activée
		and GoldCounter_MainFrame:IsShown() 			--- La frame n'est pas cachée
		and My_GC_Settings_Local.TransView == false		--- Mode non transparent 
		and GC_ToggleSwitch == false					--- Non cachée manuellement
		and FrameBackdrop.bgFile then					--- La frame est activée

		StopLoop2()  --- Stop Resting color
		StartLoop1() --- Start Red color border animation
		end

	else

		--- Stop Animation
		StopLoop1()

	end

end

function GC_UpdatedVersion()

	DEFAULT_CHAT_FRAME:AddMessage( "|cffffff00GoldCounter|r ".. GC_Locale_Text.UPDATE_MSG1 .." "..GC_Version )
	--DEFAULT_CHAT_FRAME:AddMessage( GC_Locale_Text.UPDATE_MSG2 )

end

function GC_FirstStart()

end
