do-- ADDON INFO --
--[[
Author: 
	Name: Peder Z�richo
	Curseforge Alias: MrExillion
	In Game Alias: Aesculapius
Hunter Consultant / Author Partner:
	Name: IRL ANONYMOUS
	Curseforge Alias: Fraxm
	In Game Alias: Brizz
Author Realm(s): Frostwhisper, Ravencrest
Main Distributor: CurseForge
AddOn Status: Public Alpha
Latest version: Alpha-V0.40r2-[38c7fed] 
]]
end -- ADDON INFO --
----------------------------------------------------
-- BEGIN DOCUMENT
----------------------------------------------------
--**********************************************************
-- Define AddOn in Ace using LibStub
--**********************************************************
iStableMaster = LibStub("AceAddon-3.0"):NewAddon("iStableMaster", "AceConsole-3.0", "AceEvent-3.0");
--------------------------------------------------------------------------------------------------- iStableMaster Core ---------------------------------------------------------------------------------------------


----------------------------------------------------
-- INITIALIZATION
----------------------------------------------------

--**********************************************************
-- iStableMaster UIParent,CollectionsJournal Taint functions
--**********************************************************
local function GetUIPanelAttribute(frame, name)
	if not frame:GetAttribute("UIPanelLayout-defined") then
	    local attributes = UIPanelWindows[frame:GetName()];
	    if not attributes then
			return;
	    end
		SetFrameAttributes(frame, attributes);
	end
	return frame:GetAttribute("UIPanelLayout-"..name);
end
local function SetFrameAttributes(frame, attributes)
	frame:SetAttributeNoHandler("UIPanelLayout-defined", true);
	for name, value in pairs(attributes) do
		frame:SetAttributeNoHandler("UIPanelLayout-"..name, value);
	end
end

do -- Saved Variables list
	--[[
	SavedVariablesPerCharacter: iStableMasterStableDB, iStableMasterOptionsDB iStableMasterLocalDB
	SavedVariables: iStableMasterDB, iStableMasterNewWowUpdateReloadPromt, iStableMasterStableAccountWideDB, iStableMasterAccountOptions
	]]
end -- Saved Variables List

--**********************************************************
--Name Space Declarations.
--**********************************************************
iStableMaster = iStableMaster or {};
iStableMaster.Database = {}; -- function namespace related to database
--**********************************************************
--AddOn Wide Variables (package type var = value)
--**********************************************************
iStableMaster.GlobalActiveSlotLoopValue = 5;
--**********************************************************
-- Common functions:
--**********************************************************
function iStableMaster:SetContains(set, key) 
	return set[key] ~= nil;
end -- Checks if a table contains key
function iStableMaster:ColourNormalizer(hex,...)    
	if(type(hex) == "string") then
		hex = hex:gsub("#","")
		if(string.len(hex) == 6) then
			return tonumber("0x"..hex:sub(1,2))/255, tonumber("0x"..hex:sub(3,4))/255, tonumber("0x"..hex:sub(5,6))/255;
		else
			return tonumber("0x"..hex:sub(1,2))/255, tonumber("0x"..hex:sub(3,4))/255, tonumber("0x"..hex:sub(5,6))/255, tonumber("0x"..hex:sub(7,8))/255;
		end
	elseif(type(hex) == "number" or string.Upper(select(4,...)) == "RGB") then 
		return hex/255, select(1,...)/255, select(2,...)/255, (select(3,...)or 255)/255;
	end
end -- takes a colour format(HEX,RGB or RGBA) and returns the colour as a normalized rgba-vector

-----------------------------------------------------
-- INITIALIZATION END
-----------------------------------------------------



-----------------------------------------------------
-- DATABASE CORE
-----------------------------------------------------

--**********************************************************
-- DATABASE FILTERS AND SORTS
--**********************************************************
function iStableMaster:InitFiltersWithCorruptionCheck()
	if iStableMasterDB == nil then
	iStableMasterDB = {};
	end
 iStableMaster.Database:AddPair("ActiveFilters",{},iStableMasterDB)
 iStableMaster.Database:AddPair("Type",{},iStableMasterDB.ActiveFilters)
 iStableMaster.Database:AddPair("AnyFilter",false,iStableMasterDB.ActiveFilters.Type)
 iStableMaster.Database:AddPair("API_Databased",{},iStableMasterDB.ActiveFilters.Type)
 iStableMaster.Database:AddPair("Custom",{},iStableMasterDB.ActiveFilters.Type)
 iStableMaster.Database:AddPair("FilterName",{},iStableMasterDB.ActiveFilters.Type.API_Databased)
 iStableMaster.Database:AddPair("Families",{Aqiri = true,Basilisk = true,Bat = true, Bear = true, Beetle = true,["Bird of Prey"] = true,["Blood Beast"] = true, Boar = true, Camel = true, Carapid = true,
							["Carrion Bird"] = true, Cat = true, Chimaera = true, Clefthoof = true, ["Core Hound"] = true, Courser = true, Crab = true, Crocolisk = true, 
							Devilsaur = true, Direhorn = true, Dragonhawk = true, Feathermane = true, Fox = true, Gorilla = true, Gruffhorn = true, Hound = true, Hydra = true, Hyena = true, ["Lesser Dragonkin"] = true,
							Lizard = true, Mammoth = true, Mechanical = true, Monkey = true, Moth = true, Oxen = true, Pterrordax = true, Raptor = true, Ravager = true, Ray = true,
							Riverbeast = true, Rodent = true, Scalehide = true, Scorpid = true, Serpent = true, ["Shale Beast"] = true, Spider = true, ["Spirit Beast"] = true,
							Sporebat = true, Stag = true, ["Stone Hound"] = true, Tallstrider = true, Toad = true, Turtle = true, ["Warp Stalker"] = true, Wasp = true, Waterfowl = true,["Water Strider"] = true,
							["Wind Serpent"] = true, Wolf = true, Worm = true},
	 iStableMasterDB.ActiveFilters.Type.API_Databased.FilterName)
 iStableMaster.Database:AddPair("Specialization",{Cunning = true, Tenacity = true, Ferocity = true},iStableMasterDB.ActiveFilters.Type.API_Databased.FilterName)
 iStableMaster.Database:AddPair("Diets",{Bread = true, Meat = true, ["Raw Meat"] = true, Fish = true, ["Raw Fish"] = true, Fungus = true, ["Mechanical Bits"] = true, Fruit = true, Cheese = true },iStableMasterDB.ActiveFilters.Type.API_Databased.FilterName)
 iStableMaster.Database:AddPair("FamilyAbilities",{Defense=true,BonusFamilyAbilities = true,Trick=true},iStableMasterDB.ActiveFilters.Type.API_Databased.FilterName)
 iStableMaster.Database:AddPair("FilterName",{Named = true, Favourite = true, Rarity = true, Exotic = true},iStableMasterDB.ActiveFilters.Type.Custom)
 --iStableMaster.Database:AddPair("Named",true,iStableMasterDB.ActiveFilters.Type.API_Databased.Custom.FilterName)
 --iStableMaster.Database:AddPair("Favourite",true,iStableMasterDB.ActiveFilters.Type.API_Databased.Custom.FilterName)
 --iStableMaster.Database:AddPair("Rarity",true,iStableMasterDB.ActiveFilters.Type.API_Databased.Custom.FilterName)
 --iStableMaster.Database:AddPair("Exotic",true,iStableMasterDB.ActiveFilters.Type.API_Databased.Custom.FilterName)
end
function iStableMaster:InitSortsWithCorruptionCheck()
	if iStableMasterDB == nil then
	iStableMasterDB = {};
	end
 iStableMaster.Database:AddPair("ActiveSorts",{},iStableMasterDB)
 --- Add Sorts
iStableMaster.Database:AddPair("Sort",{},iStableMasterDB.ActiveSorts)
iStableMaster.Database:AddPair("CurrentSort",{primary = "Family", secondary = "Name", tertiary = "Specialization"},iStableMasterDB.ActiveSorts)
iStableMaster.Database:AddPair("ReverseLookUpIndex",{"Name","Specialization","Family","Expansion","Diets","Favourites","Exotic","Renamed","Rarity","ActiveSlots","AnimalCompanion"},iStableMasterDB.ActiveSorts)
-- Sort[]
	iStableMaster.Database:AddPair("AnySort",false,iStableMasterDB.ActiveSorts.Sort)
	iStableMaster.Database:AddPair("Name",0,iStableMasterDB.ActiveSorts.Sort)  -- direction: -1 descending Z-A, 0 is off, 1 Ascending A-Z
	iStableMaster.Database:AddPair("Specialization",{Cunning = 1, Tenacity = 2,Ferocity = 3, Direction = 0},iStableMasterDB.ActiveSorts.Sort)  -- Spec Order 1-3, direction -1 descending, 0 off, 1 ascending : Default case => 1,2,3,1 => Cunning above Tenacity above Ferocity if diretion < 0 order, is flipped.
	iStableMaster.Database:AddPair("Family",{["Aqiri"] = 1,["Basilisk"] = 2,["Bat"] = 3,["Bear"] = 4,["Beetle"] = 5,["Bird of Prey"] = 6,["Blood Beast"] = 7,["Boar"] = 8,["Camel"] = 9,["Carapid"] = 10,["Carrion Bird"] = 11,["Cat"] = 12,["Chimaera"] = 13,["Clefthoof"] = 14,["Core Hound"] = 15, ["Courser"] = 16,["Crab"] = 17,["Crocolisk"] = 18,["Devilsaur"] = 19,["Direhorn"] = 20,["Dragonhawk"] = 21,
			["Feathermane"] = 22,["Fox"] = 23,["Gorilla"] = 24,["Gruffhorn"] = 25,["Hound"] = 26,["Hydra"] = 27,["Hyena"] = 28,["Lizard"] = 29, ["Lesser Dragonkin"] = 30,["Mammoth"] = 31,["Mechanical"] = 32,["Monkey"] = 33,["Moth"] = 34,["Oxen"] = 35,["Pterrordax"] = 36,["Raptor"] = 37,["Ravager"] = 38,["Ray"] = 39,["Riverbeast"] = 40,["Rodent"] = 41,["Scalehide"] = 42,["Scorpid"] = 43,["Serpent"] = 44,["Shale Beast"] = 45,["Spider"] = 46,["Spirit Beast"] = 47,
			["Sporebat"] = 48,["Stag"] = 49,["Stone Hound"] = 50,["Tallstrider"] = 51,["Toad"] = 52,["Turtle"] = 53,["Warp Stalker"] = 54,["Wasp"] = 55, ["Waterfowl"] = 56, ["Water Strider"] = 57,["Wind Serpent"] = 58,["Wolf"] = 59,["Worm"] = 60, Direction = 1},iStableMasterDB.ActiveSorts.Sort)   -- direction: -1 descending 58-1, 0 is off, 1 Ascending 1-58
	iStableMaster.Database:AddPair("Expansion",{Classic = 1, TBC = 2, WOTLK = 3, CATA = 4, MOP = 5, WOD = 6, LEGION = 7, BFA = 8, SL = 9, DF = 10, Direction = 1},iStableMasterDB.ActiveSorts.Sort) -- Expansion Order 1-9, direction -1 descending, 0 off, 1 ascending : Default case => 1,2,(...),9, -1 => Latest Expansions Above Earliest Expansions if diretion > 0, order is flipped.
	iStableMaster.Database:AddPair("Diets", 1,iStableMasterDB.ActiveSorts.Sort) -- direction: -1 descending Many_Food_Types-Few_Food_Types, 0 is off, 1 Ascending Few_Food_Types-Many_Food_Types
	iStableMaster.Database:AddPair("Favourites", 1,iStableMasterDB.ActiveSorts.Sort) -- direction: -1 descending IsNotFavourite-IsFavourite, 0 is off, 1 Ascending IsFavourite-IsNotFavourite
	iStableMaster.Database:AddPair("Exotic", 1,iStableMasterDB.ActiveSorts.Sort) -- direction: -1 descending IsNotExotic-iStableMaster:IsExotic, 0 is off, 1 Ascending iStableMaster:IsExotic-IsNotExotic
	iStableMaster.Database:AddPair("Renamed", 1,iStableMasterDB.ActiveSorts.Sort)  -- direction: -1 descending IsNotRenamed-IsRenamed, 0 is off, 1 Ascending IsRenamed-IsNotRenamed
	iStableMaster.Database:AddPair("Rarity", 1,iStableMasterDB.ActiveSorts.Sort) -- direction: -1 descending IsNotRare-IsRare, 0 is off, 1 Ascending IsRare-IsNotRare
	iStableMaster.Database:AddPair("ActiveSlots", 1,iStableMasterDB.ActiveSorts.Sort) -- direction: -1 descending IsNotActivePet-IsActivePet, 0 is off, 1 Ascending IsActivePet-IsNotActivePet
	iStableMaster.Database:AddPair("AnimalCompanion", 1,iStableMasterDB.ActiveSorts.Sort) -- direction: -1 descending IsNotAnimalCompanion-IsAnimalCompanion, 0 is off, 1 Ascending IsAnimalCompanion-IsNotAnimalCompanion

end
--**********************************************************
-- DATABASE CONSTANTS
--**********************************************************
function iStableMaster:InitConstantsWithCorruptionCheck()
	if iStableMasterDB == nil then
	iStableMasterDB = {};
	end
 iStableMaster.Database:AddPair("Constants",{},iStableMasterDB)
-- Add Constants
	iStableMaster.Database:AddPair("ColourScheme",{},iStableMasterDB.Constants)
		-- ColourScheme[]
			iStableMaster.Database:AddPair("Default",
				{LightGreen = "8FB261FF",Green = "4A5C33FF",DarkGreen = "344943FF",Blue = "2A3F66FF", DarkBlue = "141133FF",
				BlackTintedBlue = "0C1019FF",BoarderGreen = "334D33FF",BoarderBlue = "33464DFF"},
				iStableMasterDB.Constants.ColourScheme) -- these should be named or indexed based on their use not their colour-- this bit of code seems to have no effect, it might be the loading stack move to function properly and Init on enable.
			iStableMaster.Database:AddPair("C_STABLES_COLLECTION",{Title = "Stables", Tab = "Stable Master"}  --Contents = _G["StablesCollection"]};
				,iStableMasterDB.Constants)
			iStableMaster.Database:AddPair("CALL_PET_SPELL_IDS",{
				0883,
				83242,
				83243,
				83244,
				83245,
				},iStableMasterDB.Constants)

--iStableMasterDB["Constants"]["ColourScheme"]["Default"] = {
--	LightGreen = "8FB261FF",
--	Green = "4A5C33FF",
--	DarkGreen = "344943FF",
--	Blue = "2A3F66FF",
--	BlackTintedBlue = "0C1019FF",
--};
end
--**********************************************************
-- DATABASE DYNAMICS
--**********************************************************
function iStableMaster:InitDynamicsWithCorruptionCheck()
	if iStableMasterDB == nil then
		iStableMasterDB = {};
	end
 iStableMaster.Database:AddPair("Dynamics",{},iStableMasterDB)
-- Add Dynamics
	iStableMaster.Database:AddPair("D_STABLES_COLLECTION",{},iStableMasterDB.Dynamics)

end
--**********************************************************
-- DATABASE METADATA FOR PETS PROPERTIES
--**********************************************************
function iStableMaster:InitPetPropertyData()
	if(iStableMasterDB == nil) then
		iStableMasterDB ={};
	end
	 iStableMaster.Database:AddPair("SpecializationAbilities",{},iStableMasterDB) -- this might not be a good idea given that changes to the values won't be checked, take an ability is changed in the future, then a change here will not update existing databases. Consider updating the AddPair with an optional argument which updates the value if there is a mismatch
	 iStableMaster.Database:AddPair("Tenacity",{264662, 388035},--[[264735},]] iStableMasterDB.SpecializationAbilities)
	 iStableMaster.Database:AddPair("Cunning",{264656, 53271},iStableMasterDB.SpecializationAbilities)
	 iStableMaster.Database:AddPair("Ferocity",{264663, 264667},iStableMasterDB.SpecializationAbilities)

	 iStableMaster.Database:AddPair("FamilyAbilities",{},iStableMasterDB)
	do -- I should simply always handle database with keys of pet names via PetFamilyNamesByIndex such that changes to the family names will have to be changed in as few places as possible.
	iStableMaster.Database:AddPair("Aqiri",{160065, 280151},iStableMasterDB.FamilyAbilities)
	iStableMaster.Database:AddPair("Basilisk",{263841},iStableMasterDB.FamilyAbilities)
	iStableMaster.Database:AddPair("Bat",{344348},iStableMasterDB.FamilyAbilities)
	iStableMaster.Database:AddPair("Bear",{263934},--[[94019},]]iStableMasterDB.FamilyAbilities)
	iStableMaster.Database:AddPair("Beetle",{90339},iStableMasterDB.FamilyAbilities)
	iStableMaster.Database:AddPair("Bird of Prey",{263852},--[[ 94022},]]iStableMasterDB.FamilyAbilities)
	iStableMaster.Database:AddPair("Blood Beast",{288962},iStableMasterDB.FamilyAbilities)
	iStableMaster.Database:AddPair("Boar",{263869,},iStableMasterDB.FamilyAbilities)
	iStableMaster.Database:AddPair("Camel",{341115,},iStableMasterDB.FamilyAbilities)
	iStableMaster.Database:AddPair("Carapid",{279410,279254,},iStableMasterDB.FamilyAbilities)
	iStableMaster.Database:AddPair("Carrion Bird",{24423},iStableMasterDB.FamilyAbilities)
	iStableMaster.Database:AddPair("Cat",{263892,24450},iStableMasterDB.FamilyAbilities)
	iStableMaster.Database:AddPair("Chimaera",{54644,92380},iStableMasterDB.FamilyAbilities)
	iStableMaster.Database:AddPair("Clefthoof",{160057,280069},iStableMasterDB.FamilyAbilities)
	iStableMaster.Database:AddPair("Core Hound",{263867,159788},iStableMasterDB.FamilyAbilities)
	iStableMaster.Database:AddPair("Courser",{341117},iStableMasterDB.FamilyAbilities)
	iStableMaster.Database:AddPair("Crab",{50245},iStableMasterDB.FamilyAbilities)

	iStableMaster.Database:AddPair("Crocolisk",{50433},iStableMasterDB.FamilyAbilities)
	iStableMaster.Database:AddPair("Devilsaur",{54680,159953},iStableMasterDB.FamilyAbilities)
	iStableMaster.Database:AddPair("Direhorn", {263861},iStableMasterDB.FamilyAbilities)
	iStableMaster.Database:AddPair("Dragonhawk",{263887},iStableMasterDB.FamilyAbilities)
	iStableMaster.Database:AddPair("Feathermane",{263916,160007},iStableMasterDB.FamilyAbilities)
	iStableMaster.Database:AddPair("Fox",{160011},--[[90347},]]iStableMasterDB.FamilyAbilities)
	iStableMaster.Database:AddPair("Gorilla",{263939},iStableMasterDB.FamilyAbilities)
	iStableMaster.Database:AddPair("Gruffhorn",{263921},iStableMasterDB.FamilyAbilities)
	--iStableMaster.Database:AddPair("Hound",{17253,263423},iStableMasterDB.FamilyAbilities)
	iStableMaster.Database:AddPair("Hound",{263423},iStableMasterDB.FamilyAbilities)
	iStableMaster.Database:AddPair("Hydra",{263863},iStableMasterDB.FamilyAbilities)
	iStableMaster.Database:AddPair("Hyena",{263853},iStableMasterDB.FamilyAbilities)
	iStableMaster.Database:AddPair("Lizard",{279362},iStableMasterDB.FamilyAbilities)
	iStableMaster.Database:AddPair("Lesser Dragonkin",{392622},iStableMasterDB.FamilyAbilities)
	iStableMaster.Database:AddPair("Mammoth",{49966,341118},iStableMasterDB.FamilyAbilities)
	iStableMaster.Database:AddPair("Mechanical",{263868},iStableMasterDB.FamilyAbilities)
	iStableMaster.Database:AddPair("Monkey",{160044},iStableMasterDB.FamilyAbilities)
	iStableMaster.Database:AddPair("Moth",{344353},iStableMasterDB.FamilyAbilities)
	iStableMaster.Database:AddPair("Oxen",{264023},iStableMasterDB.FamilyAbilities)
	iStableMaster.Database:AddPair("Pterrordax",{279399,160007},iStableMasterDB.FamilyAbilities)
	iStableMaster.Database:AddPair("Raptor",{263854},iStableMasterDB.FamilyAbilities)
	iStableMaster.Database:AddPair("Ravager",{263857},iStableMasterDB.FamilyAbilities)
	iStableMaster.Database:AddPair("Ray",{344349},iStableMasterDB.FamilyAbilities)
	iStableMaster.Database:AddPair("Riverbeast",{160018},iStableMasterDB.FamilyAbilities)
	iStableMaster.Database:AddPair("Rodent",{263856},--[[126364},]]iStableMasterDB.FamilyAbilities)
	iStableMaster.Database:AddPair("Scalehide",{263865},iStableMasterDB.FamilyAbilities)
	iStableMaster.Database:AddPair("Scorpid",{160060},iStableMasterDB.FamilyAbilities)
	iStableMaster.Database:AddPair("Serpent",{263904},iStableMasterDB.FamilyAbilities)
	iStableMaster.Database:AddPair("Shale Beast",{160063,279259},iStableMasterDB.FamilyAbilities)
	iStableMaster.Database:AddPair("Spider",{160067},iStableMasterDB.FamilyAbilities)
	iStableMaster.Database:AddPair("Spirit Beast",{344351,90361,90328},iStableMasterDB.FamilyAbilities)
	iStableMaster.Database:AddPair("Sporebat",{344347},iStableMasterDB.FamilyAbilities)
	iStableMaster.Database:AddPair("Stag",{344352},iStableMasterDB.FamilyAbilities)
	iStableMaster.Database:AddPair("Stone Hound",{17253,160049,267922},iStableMasterDB.FamilyAbilities)
	iStableMaster.Database:AddPair("Tallstrider",{50285},iStableMasterDB.FamilyAbilities)
	iStableMaster.Database:AddPair("Toad",{279336},iStableMasterDB.FamilyAbilities)
	iStableMaster.Database:AddPair("Turtle",{26064},iStableMasterDB.FamilyAbilities)
	iStableMaster.Database:AddPair("Warp Stalker",{35346},iStableMasterDB.FamilyAbilities)
	iStableMaster.Database:AddPair("Wasp",{263858},iStableMasterDB.FamilyAbilities)
	iStableMaster.Database:AddPair("Waterfowl",{344350,94022},iStableMasterDB.FamilyAbilities)-- formerly Crane
	iStableMaster.Database:AddPair("Water Strider",{344346,126311},iStableMasterDB.FamilyAbilities)
	iStableMaster.Database:AddPair("Wind Serpent",{264360},iStableMasterDB.FamilyAbilities)
	iStableMaster.Database:AddPair("Wolf",{263840},iStableMasterDB.FamilyAbilities)
	iStableMaster.Database:AddPair("Worm",{263446,93433},iStableMasterDB.FamilyAbilities)
	end -- FamilyAbilities[]

	 iStableMaster.Database:AddPair("BonusFamilyAbilities",{
	Cat = 24450,
	Feathermane = 160007,
	Pterrordax = 160007,
	["Spirit Beast"] = 90328
},iStableMasterDB)
	 iStableMaster.Database:AddPair("Trick",{
	Bear =94019,
	["Bird of Prey"] =94022,
	Fox =90347,
	Rodent=26364
},iStableMasterDB)
	 iStableMaster.Database:AddPair("Defense",{
	Boar =263869,
	Mechanical =263868,
	["Shale Beast"] =160063,
	["Core Hound"] =263867,
	Scalehide =263865,
	Beetle =90339,
	Carapid =279410,
	Turtle =26064
},iStableMasterDB)
	 iStableMaster.Database:AddPair("DietIconsByIndex",{
	"Interface\\ICONS\\INV_Misc_Food_08",
	"Interface\\ICONS\\INV_Misc_Food_04",
	"Interface\\ICONS\\INV_Misc_Food_75",
	"Interface\\ICONS\\INV_Misc_Food_19",
	"Interface\\ICONS\\INV_Mushroom_07",
	"Interface\\ICONS\\INV_Misc_Food_18",
	"Interface\\ICONS\\INV_Misc_Gear_08",
	"Interface\\ICONS\\INV_Misc_Fish_07",
	"Interface\\ICONS\\INV_Misc_Food_72"
	 } -- by Alphabetical order of diets
	,iStableMasterDB)
	 iStableMaster.Database:AddPair("OtherFilterIconsByIndex",{
	132161,
	"Interface\\ICONS\\INV_Misc_Note_04",
	"Interface\\AddOns\\iStableMaster\\BlizzStar 256x256 Yellow 3",
	--3743188,
	590339,
	2437248
	 } -- by order of the filters
	,iStableMasterDB)
	 iStableMaster.Database:AddPair("FamilyIconsByFamilyID",{
	--	236195, 877476, 132182, 132183, 625905, 1044501, 132201, 132192, 454771, 877482,
	--	132200, 132191, 877480, 1044794, 236192, 236190, 236165, 132254, 132193, 1687702,
	--		1		2		3		4		5		6		7		8		9		10
	--	1044490, 132203, 929300, 132190, 132184, 2143073, 2011146, 463493, 877478, 797547,
	--	132202, 132197, 132196, 132194, 132185, 616693, 1624590, 2027936, 877479, 877477,
	--	644001, 643423, 646378, 458223, 236193, 236191, 136040, 133570, 132247, 132198,
	--	132189, 132188, 804969, 132199, 877481, 236196, 236197, 132195, 132187, 132186

	236195,
	877476,
	132182,
	132183,
	133570,
	132192,
	1687702,
	132184,
	454771,
	2011146,
	132200,
	132185,
	236190,
	1044794,
	236191,
	2143073,
	132186,
	132187,
	236192,
	877480,
	132188,
	929300,
	458223,
	132189,
	877477,
	877481,
	463493,
	132190,
	2027936,
	797547,
	132254,
	132247,
	877482,
	236193,
	616693,
	1624590,
	132193,
	132194,
	132191,
	1044490,
	644001,
	646378,
	132195,
	136040,
	877478,
	132196,
	236165,
	132197,
	1044501,
	625905,
	132198,
	804969,
	132199,
	132201,
	236196,
	877479,
	643423,
	132202,
	132203,
	236197 

},iStableMasterDB)
	 iStableMaster.Database:AddPair("FamilyIcons",{
	Aqiri        = 236195,
	Basilisk     = 877476,
	Bat          = 132182,
	Bear         = 132183,
	Beetle       = 133570,
	["Bird of Prey"] = 132192,
	["Blood Beast"]  = 1687702,
	Boar         = 132184,
	Camel        = 454771,
	Carapid      = 2011146,
	["Carrion Bird"] = 132200,
	Cat          = 132185,
	Chimaera     = 236190,
	Clefthoof    = 1044794,
	["Core Hound"]   = 236191,
	Courser      = 2143073,
	Crab         = 132186,
	Crocolisk    = 132187,
	Devilsaur    = 236192,
	Direhorn     = 877480,
	Dragonhawk   = 132188,
	Feathermane  = 929300,
	Fox          = 458223,
	Gorilla      = 132189,
	Gruffhorn    = 877477,
	Hound        = 877481,
	Hydra        = 463493,
	Hyena        = 132190,
	Lizard       = 2027936,
	["Lesser Dragonkin"] = 797547,
	Mammoth      = 132254,
	Mechanical   = 132247,
	Monkey       = 877482,
	Moth         = 236193,
	Oxen         = 616693,
	Pterrordax   = 1624590,
	Raptor       = 132193,
	Ravager      = 132194,
	Ray          = 132191,
	Riverbeast   = 1044490,
	Rodent       = 644001,
	Scalehide    = 646378,
	Scorpid      = 132195,
	Serpent      = 136040,
	["Shale Beast"]  = 877478,
	Spider       = 132196,
	["Spirit Beast"] = 236165,
	Sporebat	 = 132197,
	Stag = 1044501,
	["Stone Hound"]  = 625905,
	Tallstrider  = 132198,
	Toad         = 804969,
	Turtle       = 132199,
	["Warp Stalker"] = 132201,
	Wasp         = 804969,
	Waterfowl    = 877479, -- formerly crane
	["Water Strider"] = 643423,
	["Wind Serpent"] = 132202,
	Wolf         = 132203,
	Worm         = 236197 

	 },iStableMasterDB)
 	 iStableMaster.Database:AddPair("PetFamilyNamesByIndex",{"Aqiri","Basilisk","Bat","Bear","Beetle","Bird of Prey","Blood Beast","Boar","Camel","Carapid","Carrion Bird","Cat","Chimaera","Clefthoof","Core Hound", "Courser","Crab","Crocolisk","Devilsaur","Direhorn","Dragonhawk",
	"Feathermane","Fox","Gorilla","Gruffhorn","Hound","Hydra","Hyena","Lizard","Lesser Dragonkin","Mammoth","Mechanical","Monkey","Moth","Oxen","Pterrordax","Raptor","Ravager","Ray","Riverbeast","Rodent","Scalehide","Scorpid","Serpent","Shale Beast","Spider","Spirit Beast",
	"Sporebat","Stag","Stone Hound","Tallstrider","Toad","Turtle","Warp Stalker","Wasp","Waterfowl","Water Strider","Wind Serpent","Wolf","Worm"},iStableMasterDB)

end
--**********************************************************
-- DATABASE ADDON SETTINGS PER CHARACTER
--**********************************************************
function iStableMaster:InitSavedSquadsContainer()
	if iStableMasterStableDB == nil then
		iStableMasterStableDB = {};
	end
	iStableMaster.Database:AddPair("SavedSquads",{},iStableMasterStableDB)
end
function iStableMaster:InitOptionsDB() 
	if(iStableMasterOptionsDB == nil) then
		iStableMasterOptionsDB = {};
	end
	--AddOptions
	iStableMaster.Database:AddPair("Layout","Default",iStableMasterOptionsDB)
		iStableMaster.Database:AddPair("FilterSortTemplatesFilterScrollElements","Default",iStableMasterOptionsDB)
	iStableMaster.Database:AddPair("ScrollList",{},iStableMasterOptionsDB)
		iStableMaster.Database:AddPair("ShowActiveSlots",false,iStableMasterOptionsDB.ScrollList)	-- this is an old way of doing it should be removed in rework with templates
		iStableMaster.Database:AddPair("HideEmptyStableSlots",false,iStableMasterOptionsDB.ScrollList) -- unlike the above this one is the correct way for this, and more lines for more options should be added below in the rework	
end
--**********************************************************
-- DATABASE ADDON SETTINGS PER ACCOUNT
--**********************************************************
function iStableMaster:InitAddOnPragma()-- We set this here to avoid loading the from other classes, if need be. -- IT CANNOT BE CALLED EARLIER THAN THIS! 
   
	if iStableMasterAccountOptions == nil then
	iStableMasterAccountOptions = {};
	end
 iStableMaster.Database:AddPair("EnableAddOnForAllClasses",false,iStableMasterAccountOptions)
end -- Pseudo PragmaFunction, it means this has to be called before the Init functions inside iStableMaster:OnInitialization(), in a sense its a precall.
--**********************************************************
-- DATABASE INTERFACE(add,remove, etc.) AND CHECK FUNCTIONS
--**********************************************************
-- iStableMaster.Database:AddPair(key,value,table) 
function iStableMaster.Database:AddPair(key,value,_table)
--local testBool = (type(key) == boolean and key ~= nil)
assert(type(key)~=string,"Key is of type: "..type(key)..", Expected type: string");
if(type(value)~=boolean and value == nil) then
local checkVal = #value+1 or nil; -- this is to make sure it is not a table even if it returns nil when asked;
assert( type(checkVal) ~= number,"Value is "..type(value),checkVal..", Expected Type(s): table, number, string, boolean true or false");
end
assert(type(_table)~=table,"Table is of type: "..type(_table)..", Expected type: table");
	-- table = Table to place key in
	-- key = key to use
	-- value = table or value. if table then table must be complete with values else just value, tables should not be used.
	--local isTableOrNot = (type(value) == "table");
		--iStableMaster:Print(""..type(value).." - "..tostring(isTableOrNot));
	if ((type(value) == "table")) then 
		--iStableMaster:Print("DB is corrupt or not: "..tostring(iStableMaster:CheckForCorruptDatabase(_table[key],value)));
		-- should add unit test to assert if value is a table of tables.
		if (iStableMaster:CheckForCorruptDatabase(_table[key],value) or (#value == 0 and _table[key] == nil))then -- if table has error then do block
			_table[key] = nil;
			_table[key] = value;
			return;
		end
		
	elseif(not (iStableMaster:SetContains(_table,key))) then -- check if the key exist and if it doesn't then do block
		_table[key] = value;
	elseif((iStableMaster:SetContains(_table,key))) then
		-- do nothing
		return;

	else
		-- do nothing
		assert(nil, "iStableMaster.Database:AddPair has run with an unexpected Value: "..tostring(value))

		
	end
end -- it only sets defaults if it doesn't exist this is the best way to do it. So that means it calls the CheckDatabase Function
-- iStableMaster.Database:CheckForCorruptDatabase(table,controltable)
function iStableMaster:CheckForCorruptDatabase(DatabaseTable,ControlTable) 
	local result = false;
	if(DatabaseTable == nil) then 
		return true;
	end
	for i=1,iStableMaster:StringKeyTableLengthI(DatabaseTable) do
		for k,v in pairs(ControlTable) do 
			if not (iStableMaster:SetContains(DatabaseTable,k)) then
				result = true;

			end
		end

	end
	return result;

end -- Compares table against control table and returns false if one or more keys are missing.
--**********************************************************
-- DATABASE SETUP COMPLETE ------------------------
--**********************************************************
--**********************************************************
-- DATABASE GETTER AND SETTER FUNCTIONS
--**********************************************************
function iStableMaster:SetSortPriority(p1,p2,p3) -- bugged somehow I have no clue why but using nil still sets the filed to 0.

	if p1 == nil then

	elseif type(p1) == "string" then
		iStableMasterDB["ActiveSorts"]["CurrentSort"].primary = p1;

	else
		iStableMasterDB["ActiveSorts"]["CurrentSort"].primary = 0;

	end

	if p2 == nil then
	elseif type(p2) == "string" then
		iStableMasterDB["ActiveSorts"]["CurrentSort"].secondary = p2;
	else
		iStableMasterDB["ActiveSorts"]["CurrentSort"].secondary = 0;
	end

	if p3 == nil then 
	elseif type(p3) == "string" then
		iStableMasterDB["ActiveSorts"]["CurrentSort"].tertiary = p3;
	else
		iStableMasterDB["ActiveSorts"]["CurrentSort"].tertiary = 0;

	end

end
function iStableMaster:GetSortPriority(index,index2,index3)
	local tempOut = {};

	if(iStableMasterDB["ActiveSorts"]["CurrentSort"].primary ~= 0) then

		tempOut[1] = iStableMasterDB["ActiveSorts"]["ReverseLookUpIndex"][iStableMasterDB["ActiveSorts"]["CurrentSort"].primary];

	end

	if(index2 == nil) then
		return tempOut;
	else
		if(iStableMasterDB["ActiveSorts"]["CurrentSort"].secondary ~= 0) then

			tempOut[2] = iStableMasterDB["ActiveSorts"]["ReverseLookUpIndex"][iStableMasterDB["ActiveSorts"]["CurrentSort"].secondary];

		end

	end

	if(index3 == nil) then 
		return tempOut;
	else
		if(iStableMasterDB["ActiveSorts"]["CurrentSort"].tertiary ~= 0) then

			tempOut[3] = iStableMasterDB["ActiveSorts"]["ReverseLookUpIndex"][iStableMasterDB["ActiveSorts"]["CurrentSort"].tertiary];

		end

	end
	if (iStableMasterDB["ActiveSorts"]["CurrentSort"].primary == 0) then
		return false; -- This should never be reached!

	end



	return tempOut;
end

function iStableMaster:SetSortDirection(sortby,direction)

	if(sortby == "Specialization" or sortby == "Expansion" or sortby == "Family") then

		iStableMasterDB["ActiveSorts"]["Sort"][sortby]["Direction"] = direction;

	else
		iStableMasterDB["ActiveSorts"]["Sort"][sortby] = direction;



	end

end
function iStableMaster:GetSortDirection(sortby)

	if(sortby == "Specialization" or sortby == "Expansion" or sortby == "Family") then

		return iStableMasterDB["ActiveSorts"]["Sort"][sortby]["Direction"];

	else
		return iStableMasterDB["ActiveSorts"]["Sort"][sortby];



	end

end

function iStableMaster:SetSpecializationSort(l_Cunning,l_Tenacity,l_Ferocity,l_Direction) 
	local temp = {l_Cunning,l_Tenacity,l_Ferocity,l_Direction};

	iStableMaster:SetSortingValue("Specialization", temp);

end

function iStableMaster:SetExpansionSort(l_Classic, l_TBC, l_WOTLK, l_CATA, l_MOP, l_WOD, l_LEGION, l_BFA, l_SL, l_DF, l_Direction) 
	local temp = {l_Classic, l_TBC, l_WOTLK, l_CATA, l_MOP, l_WOD, l_LEGION, l_BFA, l_SL, l_DF, l_Direction};

	iStableMaster:SetSortingValue("Expansion", temp);

end

function iStableMaster:SetSortingValue(type, value)

	if type == "AnySort" then
		iStableMasterDB["ActiveSorts"]["Sort"].AnySort = value;
	elseif type == "Specialization" then
		iStableMasterDB["ActiveSorts"]["Sort"].Specialization = value; -- value is a table here befitting its dimensions
	elseif type == "Expansion" then
		iStableMasterDB["ActiveSorts"]["Sort"].Expansion = value; -- value is a table here befitting its dimensions
	elseif type == "Name" then
		iStableMasterDB["ActiveSorts"]["Sort"].Name = value;
	elseif type == "Family" then
		iStableMasterDB["ActiveSorts"]["Sort"].Family = value;
	elseif type == "Diets" then
		iStableMasterDB["ActiveSorts"]["Sort"].Diets = value;
	elseif type == "Favourites" then
		iStableMasterDB["ActiveSorts"]["Sort"].Favourites = value;
	elseif type == "Exotic" then
		iStableMasterDB["ActiveSorts"]["Sort"].Exotic = value;
	elseif type == "Renamed" then
		iStableMasterDB["ActiveSorts"]["Sort"].Renamed = value;
	elseif type == "Rarity" then
		iStableMasterDB["ActiveSorts"]["Sort"].Rarity = value;
	elseif type == "ActiveSlots" then
		iStableMasterDB["ActiveSorts"]["Sort"].ActiveSlots = value;
	elseif type == "AnimalCompanion" then
		iStableMasterDB["ActiveSorts"]["Sort"].AnimalCompanion = value;
	else


	end

end
function iStableMaster:GetSortingValue(type,tableIndex)
	if type == "AnySort" then
		return iStableMasterDB["ActiveSorts"]["Sort"].AnySort;
	elseif type == "Specialization" then
		return iStableMasterDB["ActiveSorts"]["Sort"].Specialization[tableIndex]; -- value is a table here befitting its dimensions, using 4 to get the value right
	elseif type == "Expansion" then
		return iStableMasterDB["ActiveSorts"]["Sort"].Expansion; -- value is a table here befitting its dimensions
	elseif type == "Name" then
		return iStableMasterDB["ActiveSorts"]["Sort"].Name;
	elseif type == "Family" then
		return iStableMasterDB["ActiveSorts"]["Sort"].Family[tableIndex];
	elseif type == "Diets" then
		return iStableMasterDB["ActiveSorts"]["Sort"].Diets;
	elseif type == "Favourites" then
		return iStableMasterDB["ActiveSorts"]["Sort"].Favourites;
	elseif type == "Exotic" then
		return iStableMasterDB["ActiveSorts"]["Sort"].Exotic;
	elseif type == "Renamed" then
		return iStableMasterDB["ActiveSorts"]["Sort"].Renamed;
	elseif type == "Rarity" then
		return iStableMasterDB["ActiveSorts"]["Sort"].Rarity;
	elseif type == "ActiveSlots" then
		return iStableMasterDB["ActiveSorts"]["Sort"].ActiveSlots;
	elseif type == "AnimalCompanion" then
		return iStableMasterDB["ActiveSorts"]["Sort"].AnimalCompanion;
	else


	end

end

function iStableMaster:SetFilterValue(type, value)

	--if(iStableMasterDB == nil) then
	--filterNil = true;
	--sortsNil = true;
	--else
	--if(iStableMasterDB.ActiveFilters == nil)
	--then filtersNil = true; else
	--filterNil = nil; end

	--if(iStableMasterDB.ActiveSorts == nil)
	--then sortsNil = true; else
	--sortsNil = nil; end
	--end
	--print(filterNil,sortsNil);
	--iStableMaster:InitFilters();
	--iStableMaster:InitSorts();


	if type == "AnyFilter" then
		iStableMasterDB["ActiveFilters"]["Type"].AnyFilter = value;
	elseif type == "Cunning" then
		iStableMasterDB["ActiveFilters"]["Type"].API_Databased.FilterName.Specialization[type] = value;
	elseif type == "Tenacity" then
		iStableMasterDB["ActiveFilters"]["Type"].API_Databased.FilterName.Specialization[type] = value;
	elseif type == "Ferocity" then
		iStableMasterDB["ActiveFilters"]["Type"].API_Databased.FilterName.Specialization[type] = value;

		-- families


	elseif iStableMaster:SetContains(iStableMasterDB["ActiveFilters"]["Type"].API_Databased.FilterName.Families, type) then
		iStableMasterDB["ActiveFilters"]["Type"].API_Databased.FilterName.Families[type] = value;




		-- foods

	elseif type == "Bread" then
		iStableMasterDB["ActiveFilters"]["Type"].API_Databased.FilterName.Diets[type] = value;
	elseif type == "Meat" then
		iStableMasterDB["ActiveFilters"]["Type"].API_Databased.FilterName.Diets[type] = value;

	elseif type == "Raw Meat" then
		iStableMasterDB["ActiveFilters"]["Type"].API_Databased.FilterName.Diets[type] = value;

	elseif type == "Fish" then
		iStableMasterDB["ActiveFilters"]["Type"].API_Databased.FilterName.Diets[type] = value;

	elseif type == "Raw Fish" then
		iStableMasterDB["ActiveFilters"]["Type"].API_Databased.FilterName.Diets[type] = value;
	elseif type == "Fungus" then
		iStableMasterDB["ActiveFilters"]["Type"].API_Databased.FilterName.Diets[type] = value;
	elseif type == "Mechanical Bits" then
		iStableMasterDB["ActiveFilters"]["Type"].API_Databased.FilterName.Diets[type] = value;
	elseif type == "Fruit" then
		iStableMasterDB["ActiveFilters"]["Type"].API_Databased.FilterName.Diets[type] = value;
	elseif type == "Cheese" then
		iStableMasterDB["ActiveFilters"]["Type"].API_Databased.FilterName.Diets[type] = value;
		--  FamilyAbilities
	elseif iStableMaster:SetContains(iStableMasterDB["ActiveFilters"]["Type"].API_Databased.FilterName.FamilyAbilities,type) then
		iStableMasterDB["ActiveFilters"]["Type"].API_Databased.FilterName.FamilyAbilities[type] = value;
		
		-- CUSTOM
	elseif type == "ActiveSlots" then
		iStableMasterOptionsDB["ScrollList"]["ShowActiveSlots"] = value;
	elseif type == "Named" then
		iStableMasterDB["ActiveFilters"]["Type"].Custom.FilterName[type] = value;
	elseif type == "Favourite" then
		iStableMasterDB["ActiveFilters"]["Type"].Custom.FilterName[type] = value;
	elseif type == "Rarity" then
		iStableMasterDB["ActiveFilters"]["Type"].Custom.FilterName[type] = value;
	elseif type == "Exotic" then
		iStableMasterDB["ActiveFilters"]["Type"].Custom.FilterName[type] = value;




	else


	end

end
function iStableMaster:GetFilterValue(input)
	--print("GETTING IT", iStableMaster:SetContains(iStableMasterDB["ActiveFilters"]["Type"].API_Databased.FilterName.Families, type));
	--iStableMaster:InitFilters();
	--iStableMaster:InitSorts();

	if input == "AnyFilter" then
		return iStableMasterDB["ActiveFilters"]["Type"].AnyFilter;
	elseif input == "Cunning" then
		return iStableMasterDB["ActiveFilters"]["Type"].API_Databased.FilterName.Specialization[input];
	elseif input == "Tenacity" then
		return iStableMasterDB["ActiveFilters"]["Type"].API_Databased.FilterName.Specialization[input];
	elseif input == "Ferocity" then
		return iStableMasterDB["ActiveFilters"]["Type"].API_Databased.FilterName.Specialization[input];
	elseif input == "Diets" then
		return iStableMasterDB["ActiveFilters"]["Type"].API_Databased.FilterName.Diets;

		-- families

	elseif iStableMaster:SetContains(iStableMasterDB["ActiveFilters"]["Type"].API_Databased.FilterName.Families, input) then
		return iStableMasterDB["ActiveFilters"]["Type"].API_Databased.FilterName.Families[input];

		-- foods

	elseif input == "Bread" then
		return iStableMasterDB["ActiveFilters"]["Type"].API_Databased.FilterName.Diets[input];
	elseif input == "Meat" then
		return iStableMasterDB["ActiveFilters"]["Type"].API_Databased.FilterName.Diets[input];

	elseif input == "Raw Meat" then
		return iStableMasterDB["ActiveFilters"]["Type"].API_Databased.FilterName.Diets[input];

	elseif input == "Fish" then
		return iStableMasterDB["ActiveFilters"]["Type"].API_Databased.FilterName.Diets[input];

	elseif input == "Raw Fish" then
		return iStableMasterDB["ActiveFilters"]["Type"].API_Databased.FilterName.Diets[input];
	elseif input == "Fungus" then
		return iStableMasterDB["ActiveFilters"]["Type"].API_Databased.FilterName.Diets[input];
	elseif input == "Mechanical Bits" then
		return iStableMasterDB["ActiveFilters"]["Type"].API_Databased.FilterName.Diets[input];
	elseif input == "Fruit" then
		return iStableMasterDB["ActiveFilters"]["Type"].API_Databased.FilterName.Diets[input];
	elseif input == "Cheese" then
		return iStableMasterDB["ActiveFilters"]["Type"].API_Databased.FilterName.Diets[input];
		-- FamilyAbilities
	elseif iStableMaster:SetContains(iStableMasterDB["ActiveFilters"]["Type"].API_Databased.FilterName.FamilyAbilities,input) then
		return iStableMasterDB["ActiveFilters"]["Type"].API_Databased.FilterName.FamilyAbilities[input];


		-- CUSTOM
	elseif input == "ActiveSlots" then
		return iStableMasterOptionsDB["ScrollList"]["ShowActiveSlots"];
	elseif input == "Named" then
		return iStableMasterDB["ActiveFilters"]["Type"].Custom.FilterName[input];
	elseif input == "Favourite" then
		return iStableMasterDB["ActiveFilters"]["Type"].Custom.FilterName[input];
	elseif input == "Rarity" then
		return iStableMasterDB["ActiveFilters"]["Type"].Custom.FilterName[input];
	elseif input == "Exotic" then
		return iStableMasterDB["ActiveFilters"]["Type"].Custom.FilterName[input];
		--elseif input == "ActiveSlots" then
		--return iStableMasterDB["ActiveFilters"]["Type"].Custom.FilterName[input];

	else

		return false;

	end


end

function iStableMaster:GetDBColour(table,key)

	return iStableMaster:ColourNormalizer(iStableMasterDB["Constants"]["ColourScheme"][table][key]);

end

------------------------------------------------
-- DATABASE CORE END
------------------------------------------------



------------------------------------------------
-- DATABASE <-> VOLATILE PET INFO
------------------------------------------------

function iStableMaster:InitPetInfoToWTF()


	local currentSpec = GetSpecialization();
	--local currentSpecName = select(2, GetSpecializationInfo(currentSpec));
	--local id, currentSpecName, description, icon, background, role = GetSpecializationInfo(currentSpec, false, false);
	--print(currentSpec);
	currentSpecName = {
		"Beast Mastery",
		"Marksmanship",
		"Survival",

	};

	
	
	GlobalSpecialization = currentSpecName[currentSpec];
	
	



	--iStableMasterDB["Dynamics"]["D_STABLES_COLLECTION"]["ActiveSlotLoopValue"] = 5;
	--print(iStableMasterDB["Dynamics"]["Specialization"]);
	if(GlobalSpecialization == "Beast Mastery") then 
		iStableMaster.GlobalActiveSlotLoopValue = 6;

	else
		iStableMaster.GlobalActiveSlotLoopValue = 5;

	end -- this is a strange place to handle this!
	iStableMasterDB["Dynamics"]["D_STABLES_COLLECTION"]["ActiveSlotLoopValue"] = iStableMaster.GlobalActiveSlotLoopValue;
	

	if (iStableMasterStableDB["PetInfo"] == nil) then

		iStableMasterStableDB["PetInfo"] = {};

	end
	

	for i=1,205,1 do
		--local button = _G["PetStableStabledPet"..i];
		
		


		if(i < 6) then
			local petSlot = PetStable_GetPetSlot(i, true);
			local l_icon, l_name, l_level, l_family, l_talent = GetStablePetInfo(i);
			--if(iStableMasterStableDB["Petslots"]["Slot"..i] == nil) then
			--iStableMasterStableDB["Petslots"]["Slot"..i] = petSlot;
			--end
			local l_abilities = {talent, family, bonus}
			l_abilities["talent"] = iStableMasterDB["SpecializationAbilities"][l_talent];
			l_abilities["family"] = iStableMasterDB["FamilyAbilities"][l_family];
			l_abilities["bonus"] = {"N/A"}; --iStableMasterStableDB["SpecializationAbilities"][l_talent]; 

			if(nil ~= l_icon) then else l_icon = "N/A" end
			if(nil ~= l_name) then else l_name = "N/A" end
			if(nil ~= l_level) then else l_level = "N/A" end
			if(nil ~= l_family) then else l_family = "N/A" end
			if(nil ~= l_talent) then else l_talent = "N/A" end
			if(nil ~= l_abilities["talent"]) then else l_abilities["talent"] = {"N/A"}; end
			if(nil ~= l_abilities["family"]) then else l_abilities["family"] = {"N/A"}; end		
			if(nil ~= l_abilities["bonus"]) then else l_abilities["bonus"] = {"N/A"}; end
			if tContains(l_abilities["talent"],264735) then  -- UPDATE SPEC abilities in DF.
				for k, v in pairs(l_abilities["talent"]) do
					if v == 264735 then 
						l_abilities["talent"][k] = 388035;
						--print("Problem Found");
					else	
						--print("found no problem");
						--l_abilities = iStableMasterStableDB["PetInfo"]["StableSlot"..petSlot]["abilities"];
					end
				end
			end


			if(iStableMaster.ScrollFrameArrElem ~= nil) then 
				--- this may be an issue in the future

				--l_favourite = iStableMaster.ScrollFrameArrElem["ScrollElementChild"..i]["PetInfo"]["favourite"];
				--l_inStables = iStableMaster.ScrollFrameArrElem["ScrollElementChild"..i]["PetInfo"]["inStables"];

			end


			if(iStableMasterStableDB["PetInfo"]["ActiveSlot"..petSlot] == nil) then
				local l_favourite = false;
				local l_inStables = false;
				if(nil ~= l_favourite) then else l_favourite = false end
				if(nil ~= l_inStables) then else l_inStables = false end

				iStableMasterStableDB["PetInfo"]["ActiveSlot"..petSlot] = {icon = l_icon, name = l_name, level = l_level, family = l_family, talent = l_talent, favourite = l_favourite, inStables = l_inStables, Slot = i,abilities = l_abilities};
			end
		else

			local petSlot = (i - 5);
			local l_icon, l_name, l_level, l_family, l_talent = GetStablePetInfo(i);

			local l_abilities = {talent, family, bonus}
			l_abilities["talent"] = iStableMasterDB["SpecializationAbilities"][l_talent];
			l_abilities["family"] = iStableMasterDB["FamilyAbilities"][l_family];
			l_abilities["bonus"] = {"N/A"}; --iStableMasterDB["SpecializationAbilities"][l_talent]; 
			--if(iStableMasterStableDB["Petslots"]["Slot"..i] == nil) then
			--iStableMasterStableDB["Petslots"]["Slot"..i] = petSlot;
			--end
			if(nil ~= l_icon) then else l_icon = "N/A" end
			if(nil ~= l_name) then else l_name = "N/A" end
			if(nil ~= l_level) then else l_level = "N/A" end
			if(nil ~= l_family) then else l_family = "N/A" end
			if(nil ~= l_talent) then else l_talent = "N/A" end
			if(nil ~= l_abilities["talent"]) then else l_abilities["talent"] = {"N/A"}; end
			if(nil ~= l_abilities["family"]) then else l_abilities["family"] = {"N/A"}; end		
			if(nil ~= l_abilities["bonus"]) then else l_abilities["bonus"] = {"N/A"}; end
			
			
			if(iStableMaster.ScrollFrameArrElem ~= nil) then 

				--l_favourite = iStableMaster.ScrollFrameArrElem["ScrollElementChild"..i]["PetInfo"]["favourite"];
				--l_inStables = iStableMaster.ScrollFrameArrElem["ScrollElementChild"..i]["PetInfo"]["inStables"];

			end
			



			if(iStableMasterStableDB["PetInfo"]["StableSlot"..petSlot] == nil) then
				local l_favourite = false;
				local l_inStables = true;
				if(nil ~= l_favourite) then else l_favourite = false end
				if(nil ~= l_inStables) then else l_inStables = true end
				if tContains(l_abilities["talent"],264735) then  -- UPDATE SPEC abilities in DF.
					for k, v in pairs(l_abilities["talent"]) do
						if v == 264735 then 
							l_abilities["talent"][k] = 388035;
							--print("Problem Found");
						else	
							--print("found no problem");
							--l_abilities = iStableMasterStableDB["PetInfo"]["StableSlot"..petSlot]["abilities"];
						end
					end
				end
				iStableMasterStableDB["PetInfo"]["StableSlot"..petSlot] = {icon = l_icon, name = l_name, level = l_level, family = l_family, talent = l_talent, favourite = l_favourite, inStables = l_inStables, Slot = i, abilities = l_abilities};
			end

		end

	end


end -- consider Refactoring
function iStableMaster:SavePetInfoToWTF()


	for i=1,205,1 do
		--local button = _G["PetStableStabledPet"..i];
		
		


		if(i < 6) then
			local petSlot = PetStable_GetPetSlot(i, true);
			local l_icon, l_name, l_level, l_family, l_talent = GetStablePetInfo(i);
			local l_abilities = {talent, family, bonus}
			l_abilities["talent"] = iStableMasterDB["SpecializationAbilities"][l_talent];
			l_abilities["family"] = iStableMasterDB["FamilyAbilities"][l_family];
			l_abilities["bonus"] = {"N/A"}; --iStableMasterDB["SpecializationAbilities"][l_talent]; 

			--iStableMasterStableDB["Petslots"]["Slot"..i] = petSlot;
			if(nil ~= l_icon) then else l_icon = "N/A" end
			if(nil ~= l_name) then else l_name = "N/A" end
			if(nil ~= l_level) then else l_level = "N/A" end
			if(nil ~= l_family) then else l_family = "N/A" end
			if(nil ~= l_talent) then else l_talent = "N/A" end
			if(nil ~= l_abilities["talent"]) then else l_abilities["talent"] = {"N/A"}; end
			if(nil ~= l_abilities["family"]) then else l_abilities["family"] = {"N/A"}; end		
			if(nil ~= l_abilities["bonus"]) then else l_abilities["bonus"] = {"N/A"}; end

			local l_favourite
			local l_inStables;

			if(iStableMaster.ScrollFrameArrElem ~= nil) then 
				if(iStableMaster.ScrollFrameArrElem["ScrollElementChild"..i] ~= nil) then
					if(iStableMaster.ScrollFrameArrElem["ScrollElementChild"..i]["PetInfo"] ~= nil) then
						if(iStableMaster.ScrollFrameArrElem["ScrollElementChild"..i]["PetInfo"] ~= nil) then
							iStableMasterStableDB["PetInfo"]["ActiveSlot"..petSlot]["favourite"]  = iStableMaster.ScrollFrameArrElem["ScrollElementChild"..i]["PetInfo"]["favourite"];
							l_inStables = iStableMaster.ScrollFrameArrElem["ScrollElementChild"..i]["PetInfo"]["inStables"];
						end
					end
				end
			end
			--if(nil ~= l_favourite) then else l_favourite = false end
			if(nil ~= l_inStables) then else l_inStables = false end
			--l_favourite = iStableMasterStableDB["PetInfo"]["ActiveSlot"..petSlot]["favourite"]; 
			l_favourite = iStableMasterStableDB["PetInfo"]["ActiveSlot"..petSlot]["favourite"] or false; 
			
			iStableMasterStableDB["PetInfo"]["ActiveSlot"..petSlot] = {icon = l_icon, name = l_name, level = l_level, family = l_family, talent = l_talent, favourite = l_favourite, inStables = l_inStables, Slot = i,  abilities = l_abilities};
		else

			local petSlot = (i - 5);
			local l_icon, l_name, l_level, l_family, l_talent = GetStablePetInfo(i);
			local l_abilities = {talent, family, bonus}
			l_abilities["talent"] = iStableMasterDB["SpecializationAbilities"][l_talent];
			l_abilities["family"] = iStableMasterDB["FamilyAbilities"][l_family];
			l_abilities["bonus"] = {"N/A"}; --iStableMasterDB["SpecializationAbilities"][l_talent]; 

			--iStableMasterStableDB["Petslots"]["Slot"..i] = petSlot;
			if(nil ~= l_icon) then else l_icon = "N/A" end
			if(nil ~= l_name) then else l_name = "N/A" end
			if(nil ~= l_level) then else l_level = "N/A" end
			if(nil ~= l_family) then else l_family = "N/A" end
			if(nil ~= l_talent) then else l_talent = "N/A" end
			if(nil ~= l_abilities["talent"]) then else l_abilities["talent"] = {"N/A"}; end
			if(nil ~= l_abilities["family"]) then else l_abilities["family"] = {"N/A"}; end		
			if(nil ~= l_abilities["bonus"]) then else l_abilities["bonus"] = {"N/A"}; end			

			local l_favourite = false;
			local l_inStables = true;
			if(iStableMaster.ScrollFrameArrElem ~= nil) then 
				if(iStableMaster.ScrollFrameArrElem["ScrollElementChild"..i] ~= nil) then
					if(iStableMaster.ScrollFrameArrElem["ScrollElementChild"..i]["PetInfo"] ~= nil) then
						if(iStableMaster.ScrollFrameArrElem["ScrollElementChild"..i]["PetInfo"] ~= nil) then
							iStableMasterStableDB["PetInfo"]["StableSlot"..petSlot]["favourite"] = iStableMaster.ScrollFrameArrElem["ScrollElementChild"..i]["PetInfo"]["favourite"];
							l_inStables = iStableMaster.ScrollFrameArrElem["ScrollElementChild"..i]["PetInfo"]["inStables"] or false;
						end
					end
				end
			end
			--if(nil ~= l_favourite) then else l_favourite = false end
			if(nil ~= l_inStables) then else l_inStables = true end
			--l_favourite = iStableMasterStableDB["PetInfo"]["StableSlot"..petSlot]["favourite"]; -- somehow this is what prevents overwriting the favourite status with false.
			l_favourite = iStableMasterStableDB["PetInfo"]["StableSlot"..petSlot]["favourite"] or false; 
			
			--if tContains(l_abilities,264735) then 
			--		for k, v in pairs(l_abilities) do
			--			if v == 264735 then 
			--					l_abilities[k] = 388035;
			--					print("Problem Found");
			--			else	
			--				print("found no problem");
			--				l_abilities = l_iStableMasterStableDB["PetInfo"]["StableSlot"..petSlot]["abilities"];
			--			end
			--		end
			--end
			iStableMasterStableDB["PetInfo"]["StableSlot"..petSlot] = {icon = l_icon, name = l_name, level = l_level, family = l_family, talent = l_talent, favourite = l_favourite, inStables = l_inStables, Slot = i,  abilities = l_abilities};
		end

	end
end -- consider Refactoring
function iStableMaster:LoadPetInfoFromWTF(table,tableString)


	if (table == nil) then

		table = {};

	end

	



	for i=1,205,1 do
		
		if(i < 6) then
			local petSlot = PetStable_GetPetSlot(i, true);

			if iStableMasterStableDB["PetInfo"]["ActiveSlot"..petSlot]["icon"] ~= nil then
				table[tablestring..i]["PetInfo"]["icon"] = iStableMasterStableDB["PetInfo"]["ActiveSlot"..petSlot]["icon"];
				table[tablestring..i]["PetInfo"]["name"] = iStableMasterStableDB["PetInfo"]["ActiveSlot"..petSlot]["name"];
				table[tablestring..i]["PetInfo"]["level"] = iStableMasterStableDB["PetInfo"]["ActiveSlot"..petSlot]["level"];
				table[tablestring..i]["PetInfo"]["family"] = iStableMasterStableDB["PetInfo"]["ActiveSlot"..petSlot]["family"];
				table[tablestring..i]["PetInfo"]["talent"] = iStableMasterStableDB["PetInfo"]["ActiveSlot"..petSlot]["talent"];
				table[tablestring..i]["PetInfo"]["favourite"] = iStableMasterStableDB["PetInfo"]["ActiveSlot"..petSlot]["favourite"];
				table[tablestring..i]["PetInfo"]["inStables"] = iStableMasterStableDB["PetInfo"]["ActiveSlot"..petSlot]["inStables"];
				table[tablestring..i]["PetInfo"]["Slot"] = iStableMasterStableDB["PetInfo"]["ActiveSlot"..petSlot]["Slot"];
				table[tablestring..i]["PetInfo"]["abilities"] = iStableMasterStableDB["PetInfo"]["ActiveSlot"..petSlot]["abilities"];

				--else
				--	local l_icon, l_name, l_level, l_family, l_talent = GetStablePetInfo(i);		
				--table[tablestring..i]["PetInfo"]["icon"] = l_icon;
				--table[tablestring..i]["PetInfo"]["name"] = l_name;
				--table[tablestring..i]["PetInfo"]["level"] = l_level;
				--table[tablestring..i]["PetInfo"]["family"] = l_family;
				--table[tablestring..i]["PetInfo"]["talent"] = l_talent;
				--table[tablestring..i]["PetInfo"]["favourite"] = false;
				--table[tablestring..i]["PetInfo"]["inStables"] = false;
				--table[tablestring..i]["PetInfo"]["Slot"] = i;
				--table[tablestring..i]["PetInfo"]["abilities"] = iStableMasterStableDB["PetInfo"]["StableSlot"..petSlot]["abilities"];

				--for k, v in pairs(table[tablestring..i]["PetInfo"]["abilities"]) do
				--			if v == 264735 then 
				--					table[tablestring..i]["PetInfo"]["abilities"][k] = 388035;
				--					print("Problem Found");
				--			else	
				--				print("found no problem");
				--				table[tablestring..i]["PetInfo"]["abilities"] = iStableMasterStableDB["PetInfo"]["ActiveSlot"..petSlot]["abilities"];
				--			end
				--		end
			else
				local petSlot = (i - 5);
				if iStableMasterStableDB["PetInfo"]["ActiveSlot"..petSlot]["icon"] ~= nil then
					table[tablestring..i]["PetInfo"]["icon"] = iStableMasterStableDB["PetInfo"]["StableSlot"..petSlot]["icon"];
					table[tablestring..i]["PetInfo"]["name"] = iStableMasterStableDB["PetInfo"]["StableSlot"..petSlot]["name"];
					table[tablestring..i]["PetInfo"]["level"] = iStableMasterStableDB["PetInfo"]["StableSlot"..petSlot]["level"];
					table[tablestring..i]["PetInfo"]["family"] = iStableMasterStableDB["PetInfo"]["StableSlot"..petSlot]["family"];
					table[tablestring..i]["PetInfo"]["talent"] = iStableMasterStableDB["PetInfo"]["StableSlot"..petSlot]["talent"];
					table[tablestring..i]["PetInfo"]["favourite"] = iStableMasterStableDB["PetInfo"]["StableSlot"..petSlot]["favourite"];
					table[tablestring..i]["PetInfo"]["inStables"] = iStableMasterStableDB["PetInfo"]["StableSlot"..petSlot]["inStables"];
					table[tablestring..i]["PetInfo"]["Slot"] = iStableMasterStableDB["PetInfo"]["StableSlot"..petSlot]["Slot"];
					table[tablestring..i]["PetInfo"]["abilities"] = iStableMasterStableDB["PetInfo"]["StableSlot"..petSlot]["abilities"];
					--if tContains(table[tablestring..i]["PetInfo"]["abilities"],264735) then 
					--for k, v in pairs(table[tablestring..i]["PetInfo"]["abilities"]) do
					--	if v == 264735 then 
					--			table[tablestring..i]["PetInfo"]["abilities"][k] = 388035;
					--			--print("Problem Found");
					--	else	
					--		--print("found no problem");
					--		table[tablestring..i]["PetInfo"]["abilities"] = iStableMasterStableDB["PetInfo"]["StableSlot"..petSlot]["abilities"];
					--	end
					--end
				end
			end
		end
	end
end -- to be refactored

------------------------------------------------
-- DATABASE <-> VOLATILE PET INFO
------------------------------------------------



--------------------------------------------------
-- ADDON EXECUTION ORDER
--------------------------------------------------

--**********************************************************
-- iStableMaster Callback Event Function hooked after LOD Dependencies
--**********************************************************
function iStableMaster:PostCollectionsLoad() 
	iStableMaster:HookTab();
	--iStableMaster:InitFilters();	
	--iStableMaster:InitSorts();
	--StablesCollection_OnLoad(StablesCollection);
	if(CollectionsJournal.selectedTab == iStableMasterDB["Dynamics"]["D_STABLES_COLLECTION"]["TabId"]) then iStableMaster:StablesToggleButtonTextUpdate() end
	hooksecurefunc("CollectionsJournal_UpdateSelectedTab", function()
		if(StablesCollection:IsShown()) then
			StablesCollection_Hide();
		end 

	end );
end  
--**********************************************************
-- ACE 3.0 Event Execution Order
--**********************************************************
function iStableMaster:OnInitialize()-- Called when the addon is loaded	

	--@PRAGMAS
	iStableMaster:InitAddOnPragma() -- PRAGMAS MUST BE FIRST CALL!
	--@Welcome
			-- Print a message to the chat frame		
			if(iStableMasterAccountOptions.EnableAddOnForAllClasses or (UnitClass("player") == "Hunter")) then
				
			
			
				self:Print("Version Number: Alpha-V0.40r2-[38c7fed], Please report bugs via |cc00ff00f https://www.curseforge.com/wow/addons/istablemaster/issues |ccfffffff Any new feature requests should be requested in the same place as bug reports. You can see known issues here: |cc00ff00f https://www.curseforge.com/wow/addons/istablemaster/files ");
				self:Print("\n Be aware that using the stables with iStableMaster Deactivated, (also if you have done this in the past), will cause the Addons Saved Squads to lose track of its pets. Disband and Re-Add your squad to fix");	
			--	iStableMaster:Print("An Error has been spottet in your WTF folder: Please check the |cc00ff00f".." 'World of Warcraft\\_retail_\\WTF\\Account\\{accountnumber}\\SavedVariables\\iStableMaster.lua'".."|ccfffffff ".."while the game is closed and correct the family name for:".."AWESOME PET NAME".." Or delete the file, but this will reset all your preferences too");
			end
	--@InitializeDatabase
	iStableMaster:InitFiltersWithCorruptionCheck();
	iStableMaster:InitSortsWithCorruptionCheck();
	iStableMaster:InitConstantsWithCorruptionCheck();
	iStableMaster:InitDynamicsWithCorruptionCheck();
	iStableMaster:InitPetPropertyData();
	iStableMaster:InitSavedSquadsContainer();
	iStableMaster:InitOptionsDB();
	--@LoadSavedVariablesToRuntimeDataStructures
	if( iStableMasterStableDB == nil) then -- CONSIDER DEPRECATING AND HANDLING IT BETTER
		iStableMasterStableDB = {};	
		--iStableMasterStableDB["Petslots"] = {}; -- I Don't know why this isn't used anymore. But should be removed if i don't find out.
		iStableMasterStableDB["PetInfo"] = {}; -- would be AddPair(PetInfo, {},iStableMasterStableDB)
		iStableMaster:InitPetInfoToWTF(); -- should include above line.
	else
		iStableMaster:InitPetInfoToWTF(); -- this conditional should be handled using AddPair().
	end
end-- Called when the addon is loaded
function iStableMaster:OnEnable()-- Called when the AddOn is enabled
	--@HookAddOnToEvents
	hooksecurefunc("ClosePetStables", function() 
	end);
	hooksecurefunc("SetPetSlot", function() iStableMaster:HookSetPetSlotToTrackCompletion() end);
	if (not IsAddOnLoaded("Blizzard_Collections")) then
		LoadAddOn("Blizzard_Collections");
	end
	hooksecurefunc(_G["PetStableFrame"],"Hide", function()
		CollectionsJournal:SetAttribute("UIPanelLayout-pushable", 1)
		CollectionsJournal:SetAttribute("UIPanelLayout-allowOtherPanels", 1)
		PetStableFrame:SetAttribute("UIPanelLayout-pushable", 1)
		PetStableFrame:SetAttribute("UIPanelLayout-allowOtherPanels", 1)
	end );
	hooksecurefunc(_G["CollectionsJournal"],"Show", function()  
		-- to prevent old squad data from killing the addon if there are gaps in the squad
		local SquadLen = iStableMaster:StringKeyTableLengthI(iStableMasterStableDB["SavedSquads"])
		for k,v in pairs(iStableMasterStableDB["SavedSquads"])  do
			if(SquadLen < tonumber(select(2,strsplit("d",k)))) then
				local l_SquadLen = iStableMaster:StringKeyTableLengthI(iStableMasterStableDB["SavedSquads"]);
				iStableMasterStableDB["SavedSquads"]["Squad"..l_SquadLen] = v;
				iStableMasterStableDB["SavedSquads"]["Squad"..l_SquadLen].Name = iStableMasterStableDB["SavedSquads"][k].Name or "Squad"..l_SquadLen;
				iStableMasterStableDB["SavedSquads"]["Squad"..l_SquadLen].Name = iStableMasterStableDB["SavedSquads"][k].Icon or "Ability_Hunter_Pet_Assist";
				iStableMasterStableDB["SavedSquads"][k] = nil;
			end
		end
		iStableMaster:PostCollectionsLoad() 
	end);
	hooksecurefunc(_G["PetStableFrame"],"Show", function() 
		PetStableFrame:SetAttribute("panel-show", 1)		
		CollectionsJournal:SetAttribute("UIPanelLayout-pushable", 0)
		CollectionsJournal:SetAttribute("UIPanelLayout-allowOtherPanels", 1)
		PetStableFrame:SetAttribute("UIPanelLayout-pushable", 1)
		PetStableFrame:SetAttribute("UIPanelLayout-allowOtherPanels", 1)
		PetStableFrame:SetAttribute("UIPanelLayout-allowOtherPanels", 1)
		PetStableFrame:SetAttribute("UIPanelLayout-area", "right")		
		local point, relativeTo, relativePoint, xOfs, yOfs = PetStableFrame:GetPoint(1);
		if(xOfs < 0) then
		end
		PetStableFrame:SetPoint("TOPLEFT",1050,-154);
		HideUIPanel(GossipFrame);
		C_Timer.After(0.5, function()
			ShowUIPanel(CollectionsJournal)
			StablesCollectionsJournal_SetTab(CollectionsJournal,iStableMasterDB["Dynamics"]["D_STABLES_COLLECTION"]["TabId"]);
			PanelTemplates_SetTab(CollectionsJournal,iStableMasterDB["Dynamics"]["D_STABLES_COLLECTION"]["TabId"]);
		end);		
	end);
	hooksecurefunc(_G["CollectionsJournal"],"Show", function()
		if(UnitClass("player") ~= "Hunter") then
			if(not iStableMasterAccountOptions.EnableAddOnForAllClasses) then
				if(tonumber(GetCVar("petJournalTab")) == STABLE_COLLECTIONS_TAB_ID) then
					SetCVar("petJournalTab",CollectionsJournal.numTabs-1)
				STABLE_COLLECTIONS_TAB_ID = CollectionsJournal.numTabs-1;
				PanelTemplates_SetNumTabs(CollectionsJournal,STABLE_COLLECTIONS_TAB_ID);
				end
			end
		end
		if(UnitClass("player") == "Hunter" or iStableMasterAccountOptions.EnableAddOnForAllClasses) then
				--print(CollectionsJournalTitleText);
				if(tonumber(GetCVar("petJournalTab")) == STABLE_COLLECTIONS_TAB_ID) then
					--print("Showing Stables Collection");
					StablesCollection_Show()
				end
			
		end
	end);
	--@SafetyReloads
	iStableMaster:SafetyReload();
	--@DependentFrame_OnLoads
	iStableMaster:FilterSortFrameOnLoad();
		--@HookDependentFrameHandlersToEvents
		hooksecurefunc(_G["StablesCollection"],"Hide", function()if StablesFilterSortFrame:IsShown() then iStableMaster:ToggleFiltersFrame() end end );

	
	--@Check if enabled for non-Hunters -- and then disable addon.
	if(UnitClass("player") ~= "Hunter") then
		if(not iStableMasterAccountOptions.EnableAddOnForAllClasses) then
			self:Disable();
		end
	end
end-- Called when the AddOn is enabled
function iStableMaster:OnDisable()-- Called when the AddOn is disabled
	--@SaveRuntimeDataStructuresToSavedVariables

	--iStableMasterOptionsDB = l_iStableMasterOptionsDB; I don't think this should ever be volatile
end-- Called when the AddOn is disabled

--------------------------------------------------
-- ADDON EXECUTION ORDER END
--------------------------------------------------




------------------------------------------------------------------------------------------------iStableMaster Extensions---------------------------------------------------------------------------------------



------------------------------------------------
-- END OF DOCUMENT
------------------------------------------------
