--[[

    MonkeyQuest:
    Quest tracker.
    
    Website:	www.toctastic.net
	Author:		Trentin
	Email:		monkeymods@gmail.com

--]]



function MonkeyQuest_GetBlizzQuestIndex(strTitle)

	local numEntries, numQuests = GetNumQuestLogEntries();
	local questLogTitleText, level, questTag, suggestedGroup, isHeader, isCollapsed, isComplete, color;


	for i = 1, numQuests, 1 do

		questLogTitleText, level, questTag, suggestedGroup, isHeader, isCollapsed, isComplete = GetQuestLogTitle(i);

		if (questLogTitleText and questLogTitleText == strTitle) then
			return i;
		end
	end

	-- not found
	return -1;
end

-- Get a colour for the leaderboard item depending on how "done" it is
function MonkeyQuest_GetObjectiveColourStr(numItems, numNeeded)

	if (MonkeyQuestVars.showObjectiveColour.current == false) then
		return MonkeyAPI_RGBAToColourStr(1, 1, 1);
	end

	local colour = {};
	local colour0 = MonkeyQuestVars.objectiveColour0.current;
	local colour0plus = MonkeyQuestVars.objectiveColour0plus.current;
	local colour50 = MonkeyQuestVars.objectiveColour50.current;
	local colour100minus = MonkeyQuestVars.objectiveColour100minus.current;
	local colour100 = MonkeyQuestVars.objectiveColour100.current;


	-- first the easy ones
	if (numItems == 0) then
		return MonkeyAPI_RGBAToColourStr(colour0.r, colour0.g, colour0.b);
	end
	
	if (numItems == numNeeded) then
		return MonkeyAPI_RGBAToColourStr(colour100.r, colour100.g, colour100.b);
	end
	

	if ((numItems / numNeeded) < 0.5) then
		colour.r = colour0plus.r + ((numItems / (numNeeded / 2)) * (colour50.r - colour0plus.r));
		colour.g = colour0plus.g + ((numItems / (numNeeded / 2)) * (colour50.g - colour0plus.g));
		colour.b = colour0plus.b + ((numItems / (numNeeded / 2)) * (colour50.b - colour0plus.b));
	else
		colour.r = colour50.r + (((numItems - (numNeeded / 2)) / (numNeeded / 2)) * (colour100minus.r - colour50.r));
		colour.g = colour50.g + (((numItems - (numNeeded / 2)) / (numNeeded / 2)) * (colour100minus.g - colour50.g));
		colour.b = colour50.b + (((numItems - (numNeeded / 2)) / (numNeeded / 2)) * (colour100minus.b - colour50.b));
	end
	

	-- just incase the numbers went slightly out of range
	if (colour.r > 1.0) then
		colour.r = 1.0;
	end
	if (colour.g > 1.0) then
		colour.g = 1.0;
	end
	if (colour.b > 1.0) then
		colour.b = 1.0;
	end
	if (colour.r < 0.0) then
		colour.r = 0.0;
	end
	if (colour.g < 0.0) then
		colour.g = 0.0;
	end
	if (colour.b < 0.0) then
		colour.b = 0.0;
	end

	return MonkeyAPI_RGBAToColourStr(colour.r, colour.g, colour.b);
end
