function DSCT_SP_OnLoad()
	if getglobal("DSCTOptions") == nil then return;end
	local button1 = getglobal("DSCTOptionsSpellAlert");
	button1:SetParent("DSCTOptions");
	button1:SetPoint("TOPLEFT", "DSCTOptions", "TOPLEFT", 20 ,-200 );
end

function DSCT_SPELLALERT_SEARCH(mob, spell, search, type)	
	if(not DSCT_isParty(mob)) then
		if DSCT_Get("SHORTALERT") == 1 then
			DSCT_Display_Toggle("SHOWSPELLALERT",1,nil,DSCT_SHORTALERT..SpellAlert_Spell_head..spell..search[3]);
		else
			if (type == "BUFF") then
				DSCT_Display_Toggle("SHOWSPELLALERT",1,nil,SpellAlert_Mob_head..mob..search[2]..SpellAlert_Spell_head..spell.."|r"..DSCT_BUFF_END);
			else
				DSCT_Display_Toggle("SHOWSPELLALERT",1,nil,SpellAlert_Mob_head..mob..search[2]..SpellAlert_Spell_head..spell.."|r");
			end
		end
		DSCT_FixSpellTime(spell);
		return true;
	end
	return false;
end

function DSCT_SP_OnEvent(event, srcGUID, srcName, srcFlags, dstGUID, dstName, dstFlags, ...)
	local arg1, arg2, arg3, arg4, arg5, arg6 = srcGUID, srcName, srcFlags, dstGUID, dstName, dstFlags;
	-- start spell alert	
	if (event == "SPELL_CAST_START") then		
		if (DSCT_Get("SHOWSPELLALERT") ~= 0  and DSCT_Get("SHOWSA_BEGINCAST") == 1 and CombatLog_Object_IsA(srcFlags, COMBATLOG_FILTER_HOSTILE_UNITS, COMBATLOG_FILTER_HOSTILE_PLAYERS))then
			--DSCT_Debug(event, srcGUID, srcName, srcFlags, dstGUID, dstName, dstFlags, ...);
			DSCT_SPELLALERT_SEARCH(srcName,  select(2, ...), DSCT_SA_BEGIN_CAST);
		end
		return;
	elseif (event == "SPELL_AURA_APPLIED") then		
		local auraId, auraName, auraSchool, auraType = select(1, ...);
		--DSCT_Debug(dstName, CombatLog_Object_IsA(dstFlags, COMBATLOG_FILTER_HOSTILE_UNITS));
		if (DSCT_Get("SHOWSPELLALERT") ~= 0 and DSCT_Get("SHOWSA_GAIN") == 1 and auraType == "BUFF" and CombatLog_Object_IsA(dstFlags, COMBATLOG_FILTER_HOSTILE_UNITS, COMBATLOG_FILTER_HOSTILE_PLAYERS))then
			--DSCT_Debug(event, srcGUID, srcName, srcFlags, dstGUID, dstName, dstFlags, ...);
			DSCT_SPELLALERT_SEARCH(dstName, auraName, DSCT_SA_GAIN_BUFF, "BUFF");
		end
		return;	
	elseif event == "CHAT_MSG_MONSTER_EMOTE" then
		if(DSCT_Get("SHOWEMOTE") ~= 0) then
			local name = arg2;			
			if (name and arg1) then 
				DSCT_Display_Toggle("SHOWEMOTE",1,nil, format(arg1, name));
			end
		end
		return;
	elseif event == "CHAT_MSG_MONSTER_YELL" then
		if(DSCT_Get("SHOWYELL") ~= 0) then
			local name = arg2;
			if (not name) then
				name = DSCT_NO_TARGET;
			end
			if (arg1) then
				DSCT_Display_Toggle("SHOWYELL",1,nil,name..":  "..arg1);					
			end
		end
		return;	
	end
end

function DSCT_FixSpellTime(spellname)
	if DSCT_Get("SHOWSPELLTIMER") ~= 1 then return;end
	local bak = DENNIE_cusMessLast;
	DENNIE_cusMessLast = DENNIE_cusMessLast - 1;
	if DENNIE_cusMessLast < 1 then DENNIE_cusMessLast = 3;end
	local adat = arrCusMessData["cusMessData"..DENNIE_cusMessLast];
	if spellname then
		if DSCT_CastTime[spellname] then
			adat.SpellTime = DSCT_CastTime[spellname].t;
			adat.SpellStartTimer = adat.lastupdate;
		end
	end
	DENNIE_cusMessLast = bak;
end