-- test

local timersSetup;
local timers = {};

function GHU_GetFreeName()
	local c = 1000;
	while (true) do
		if (_G["GHU_"..c] == nil) then
			return "GHU_"..c;
		end
		c = c+1;
	end
end

function GHU_New(Type,name,arg1)
	local varName = GHU_GetFreeName();
	
	Type = strlower(Type);
	
	if Type=="skill" then
		GHU_Skill:Create(varName,name);
	elseif Type=="npc" then
		GHU_NPC:Create(varName);
	elseif Type=="mail" then
		GHU_Mail:Create(varName);
	elseif Type=="achievement" then
		GHU_Achievement:Create(varName,name);
	elseif Type=="profession" then
		error("Profession GHU dosent exsist. Use craft");
	elseif Type=="cast" then
		GHU_Cast:Create(varName);
	elseif Type=="loot" then
		GHU_Loot:Create(varName);
	elseif Type=="book" then
		GHU_Book:Create(varName);
	elseif Type=="questlog" then
		GHU_QL:Create(varName);
	elseif Type=="talent" then
		GHU_Talent:Create(varName,name,arg1); -- arg1 being icon 
	elseif Type=="craft" then
		GHU_Craft:Create(varName);
	elseif Type=="buff" then
		GHU_Buff:Create(varName);
	elseif Type=="target" then
		GHU_Target:Create(varName);
	elseif Type=="document" then
		return GHU_Document:Create();
	elseif Type=="trainer" then
		return GHU_Trainer:Create();
	elseif Type=="spellbook" then
		return GHU_Spellbook:Create();
	end
	
	if not(timersSetup) then
		local Old_Script = WorldFrame:GetScript("OnUpdate");
		WorldFrame:SetScript("OnUpdate", function(self, elapsed) Old_Script(self, elapsed); GHU_OnWF(); end);
	
	end
	
	return _G[varName];
end

function GHU_RegTimer(s,func)
	table.insert(timers,{s = s, func = func});
end

function GHU_OnWF()
	for _,t in pairs(timers) do
		--print(type(t.s));
		t.func(t.s);
	end

end

function GHU_Merge(...)
	local input = {...};
	local t = {};
	for _,v in pairs(input) do
		for name,func in pairs(v) do
			t[name] = func;
		end	
	end
	return t;
end

