local toggle = {};
toggle.on = function() 
	if (LoggingCombat()) then
		print(OStext.."Combat logging is currently enabled.")
	else
		print(OStext.."Combat logging is now enabled.")
		LoggingCombat(1)
	end
end
toggle.off = function()
	if OverSimpDB.combatlog and LoggingCombat() then
		print(OStext.."Combat logging is now disabled, however autologging is still enabled.")
		LoggingCombat(0)
	else
		if not (LoggingCombat()) then
			print(OStext.."Combat logging is currently disabled.")
		else
			print(OStext.."Combat logging is now disabled.")
			LoggingCombat(0)
		end
	end
end

local f = CreateFrame("Frame", "OS_CombatLogger")

local function ZoneCheck()
	local inInstance, itype = IsInInstance()
	if inInstance and itype == "raid" and not (LoggingCombat()) then
		LoggingCombat(1)
	else
		LoggingCombat(0)
	end
end

f:RegisterEvent("PLAYER_ENTERING_WORLD")
f:SetScript("OnEvent", function(self,event,...)
	if (event == "PLAYER_ENTERING_WORLD") then
		if OverSimpDB.combatlog then
			ZoneCheck()
		end
	end
end)

toggle.auto = function()
	OverSimpDB.combatlog = not OverSimpDB.combatlog
	if not OverSimpDB.combatlog then
		if LoggingCombat() then
			print(OStext.."Auto Combat Logging now disabled, but combat is still being logged. Type '/cl off' to stop logging combat.")
		else
			print(OStext.."Auto Combat Logging now disabled.")
		end
	else
		ZoneCheck()
		print(OStext.."Auto Combat Logging now enabled.")
	end
end

function osCL(arg)
	if type(toggle[arg]) == 'function' then 
		toggle[arg]()
	else 
		print(OStext.."Available commands are /cl 'on', 'off', or 'auto'.")
	end
end

SLASH_CL1 = "/cl";
SlashCmdList["CL"] = osCL