function LVBMStatusBars_OnUpdate(elapsed)
	if this.isUsed and LVBM.StatusBarData[this.usedBy] then
		LVBM.StatusBarData[this.usedBy].elapsed = LVBM.StatusBarData[this.usedBy].elapsed + elapsed;
		if LVBM.Options.FillUpStatusBars then
			getglobal(this:GetName().."Bar"):SetValue(LVBM.StatusBarData[this.usedBy].elapsed);
		else
			getglobal(this:GetName().."Bar"):SetValue(LVBM.StatusBarData[this.usedBy].timer - LVBM.StatusBarData[this.usedBy].elapsed);
		end
		getglobal(this:GetName().."BarTimer"):SetText(LVBM.SecondsToTime(LVBM.StatusBarData[this.usedBy].timer - LVBM.StatusBarData[this.usedBy].elapsed));
		if LVBM.StatusBarData[this.usedBy].elapsed >= LVBM.StatusBarData[this.usedBy].timer then
			if GameTooltip:IsShown() and GameTooltipTextLeft1 and GameTooltipTextLeft1:GetText() == getglobal(this:GetName().."BarText"):GetText() and ((not LVBM.StatusBarData[this.usedBy].repetitions) or LVBM.StatusBarData[this.usedBy].repetitions <= 1) then
				GameTooltip:Hide();
			end
			LVBM.EndStatusBarTimer(this.usedBy, true);
		end
	end
	
	local minValue, maxValue;
	minValue, maxValue = getglobal(this:GetName().."Bar"):GetMinMaxValues();
	getglobal(this:GetName().."BarSpark"):ClearAllPoints();
	getglobal(this:GetName().."BarSpark"):SetPoint("CENTER", (this:GetName().."Bar"), "LEFT", (((getglobal(this:GetName().."Bar"):GetValue() - elapsed) / maxValue) * getglobal(this:GetName().."Bar"):GetWidth()), 0);
	
	if GameTooltip:IsShown() and GameTooltipTextLeft1 and GameTooltipTextLeft1:GetText() == getglobal(this:GetName().."BarText"):GetText() then
		if GameTooltipTextRight2 then
			GameTooltipTextRight2:SetText(LVBM.SecondsToTime(LVBM.StatusBarData[this.usedBy].timer - LVBM.StatusBarData[this.usedBy].elapsed));
		end
		if GameTooltipTextRight3 then
			GameTooltipTextRight3:SetText(LVBM.SecondsToTime(LVBM.StatusBarData[this.usedBy].elapsed));
		end
		if GameTooltipTextLeft5 and GameTooltipTextRight5 and GameTooltipTextLeft5:GetText() == LVBM_SBT_REPETITIONS then
			if not LVBM.StatusBarData[this.usedBy].infinite then
				GameTooltipTextRight5:SetText(LVBM.StatusBarData[this.usedBy].repetitions);
			end
		end
	end
end

function LVBMStatusBars_OnEnter()
	GameTooltip:Hide();
	GameTooltip:ClearLines();
	GameTooltip_SetDefaultAnchor(GameTooltip, UIParent);
	GameTooltip:SetText(getglobal(this:GetName().."BarText"):GetText());
	GameTooltip:AddDoubleLine(LVBM_SBT_TIMELEFT, LVBM.SecondsToTime(LVBM.StatusBarData[this.usedBy].timer - LVBM.StatusBarData[this.usedBy].elapsed), NORMAL_FONT_COLOR.r, NORMAL_FONT_COLOR.g, NORMAL_FONT_COLOR.b, HIGHLIGHT_FONT_COLOR.r, HIGHLIGHT_FONT_COLOR.g, HIGHLIGHT_FONT_COLOR.b);
	GameTooltip:AddDoubleLine(LVBM_SBT_TIMEELAPSED, LVBM.SecondsToTime(LVBM.StatusBarData[this.usedBy].elapsed), NORMAL_FONT_COLOR.r, NORMAL_FONT_COLOR.g, NORMAL_FONT_COLOR.b, HIGHLIGHT_FONT_COLOR.r, HIGHLIGHT_FONT_COLOR.g, HIGHLIGHT_FONT_COLOR.b);
	GameTooltip:AddDoubleLine(LVBM_SBT_TOTALTIME, LVBM.SecondsToTime(LVBM.StatusBarData[this.usedBy].timer), NORMAL_FONT_COLOR.r, NORMAL_FONT_COLOR.g, NORMAL_FONT_COLOR.b, HIGHLIGHT_FONT_COLOR.r, HIGHLIGHT_FONT_COLOR.g, HIGHLIGHT_FONT_COLOR.b);
	if LVBM.StatusBarData[this.usedBy].isRepeating and LVBM.StatusBarData[this.usedBy].repetitions then
		if LVBM.StatusBarData[this.usedBy].infinite then
			GameTooltip:AddDoubleLine(LVBM_SBT_REPETITIONS, LVBM_SBT_INFINITE, NORMAL_FONT_COLOR.r, NORMAL_FONT_COLOR.g, NORMAL_FONT_COLOR.b, HIGHLIGHT_FONT_COLOR.r, HIGHLIGHT_FONT_COLOR.g, HIGHLIGHT_FONT_COLOR.b);
		else
			GameTooltip:AddDoubleLine(LVBM_SBT_REPETITIONS, LVBM.StatusBarData[this.usedBy].repetitions, NORMAL_FONT_COLOR.r, NORMAL_FONT_COLOR.g, NORMAL_FONT_COLOR.b, HIGHLIGHT_FONT_COLOR.r, HIGHLIGHT_FONT_COLOR.g, HIGHLIGHT_FONT_COLOR.b);
		end
	end
	if LVBM.StatusBarData[this.usedBy].startedBy and LVBM.StatusBarData[this.usedBy].startedBy ~= "UNKNOWN" then
		GameTooltip:AddDoubleLine(LVBM_SBT_BOSSMOD, LVBM.StatusBarData[this.usedBy].startedBy, NORMAL_FONT_COLOR.r, NORMAL_FONT_COLOR.g, NORMAL_FONT_COLOR.b, HIGHLIGHT_FONT_COLOR.r, HIGHLIGHT_FONT_COLOR.g, HIGHLIGHT_FONT_COLOR.b);
	end
	if LVBM.StatusBarData[this.usedBy].syncedBy and LVBM.StatusBarData[this.usedBy].syncedBy ~= LVBM_LOCAL then	
		GameTooltip:AddDoubleLine(LVBM_SBT_STARTEDBY, LVBM.StatusBarData[this.usedBy].syncedBy, NORMAL_FONT_COLOR.r, NORMAL_FONT_COLOR.g, NORMAL_FONT_COLOR.b, HIGHLIGHT_FONT_COLOR.r, HIGHLIGHT_FONT_COLOR.g, HIGHLIGHT_FONT_COLOR.b);
	else
		GameTooltip:AddDoubleLine(LVBM_SBT_STARTEDBY, UnitName("player"), NORMAL_FONT_COLOR.r, NORMAL_FONT_COLOR.g, NORMAL_FONT_COLOR.b, HIGHLIGHT_FONT_COLOR.r, HIGHLIGHT_FONT_COLOR.g, HIGHLIGHT_FONT_COLOR.b);
	end
	GameTooltip:AddLine(LVBM_SBT_RIGHTCLICK, NORMAL_FONT_COLOR.r, NORMAL_FONT_COLOR.g, NORMAL_FONT_COLOR.b);
	GameTooltip:Show();
end

function LVBMStatusBars_SetDefaultValues()
	LVBM.Options.StatusBarColor = {
		["r"] = 1.0,
		["g"] = 0.7,
		["b"] = 0.0,
		["a"] = 1.0,
	};
	LVBM.Options.StatusBarsFlippedOver = false;
	LVBM.Options.FillUpStatusBars = true;
	LVBM.Options.EnableStatusBars = true;
	LVBM.Options.StatusBarSize = {
		["Scale"] = 1,
		["Width"] = 195,
	};
end

function LVBMStatusBars_FlipOver()
	if LVBM.Options.StatusBarsFlippedOver then
		for i = 2, 10 do
			getglobal("LVBM_StatusBarTimer"..i):ClearAllPoints()
			getglobal("LVBM_StatusBarTimer"..i):SetPoint("BOTTOM", "LVBM_StatusBarTimer"..(i-1), "TOP", 0, -3);
		end
	else
		for i = 2, 10 do
			getglobal("LVBM_StatusBarTimer"..i):ClearAllPoints()
			getglobal("LVBM_StatusBarTimer"..i):SetPoint("TOP", "LVBM_StatusBarTimer"..(i-1), "BOTTOM", 0, 3);
		end
	end
end

function LVBMStatusBars_PullTogether()
	for i = 2, 10 do
		if getglobal("LVBM_StatusBarTimer"..i).isUsed and (not getglobal("LVBM_StatusBarTimer"..(i-1)).isUsed) then
			local j = i - 1;
			local barName = getglobal("LVBM_StatusBarTimer"..i).usedBy;
			local timer = LVBM.StatusBarData[barName].timer;
			local elapsed = LVBM.StatusBarData[barName].elapsed;
			local syncedBy = LVBM.StatusBarData[barName].syncedBy;
			local startedBy = LVBM.StatusBarData[barName].startedBy;
			local isRepeating = LVBM.StatusBarData[barName].isRepeating;
			local repetitions = LVBM.StatusBarData[barName].repetitions;
			getglobal("LVBM_StatusBarTimer"..i):Hide();	
			getglobal("LVBM_StatusBarTimer"..i).isUsed = false;
			getglobal("LVBM_StatusBarTimer"..i).usedBy = "";
			getglobal("LVBM_StatusBarTimer"..i).isRepeating = false;
			getglobal("LVBM_StatusBarTimer"..i).repetitions = 0;
			LVBM.StatusBarData[barName] = nil;
			
			getglobal("LVBM_StatusBarTimer"..j).isUsed = true;
			getglobal("LVBM_StatusBarTimer"..j).usedBy = barName;
			getglobal("LVBM_StatusBarTimer"..j).syncedBy = syncedBy;
			getglobal("LVBM_StatusBarTimer"..j).startedBy = startedBy;
			getglobal("LVBM_StatusBarTimer"..j).isRepeating = isRepeatinge;
			getglobal("LVBM_StatusBarTimer"..j).repetitions = repetitions;
			getglobal("LVBM_StatusBarTimer"..j.."Bar"):SetMinMaxValues(0, timer);
			if type(LVBM_SBT[barName]) == "string" then
				getglobal("LVBM_StatusBarTimer"..j.."BarText"):SetText(LVBM_SBT[barName]);
			else
				getglobal("LVBM_StatusBarTimer"..j.."BarText"):SetText(barName);
			end
			getglobal("LVBM_StatusBarTimer"..j.."BarTimer"):SetText(LVBM.SecondsToTime(timer));
			getglobal("LVBM_StatusBarTimer"..j):Show();
	
			LVBM.StatusBarData[barName] = {
				["elapsed"] = elapsed,
				["timer"] = timer,
				["barId"] = j,
				["syncedBy"] = syncedBy,
				["startedBy"] = startedBy,
				["isRepeating"] = isRepeating,
				["repetitions"] = repetitions,
			};

		end
	end
end

function LVBMStatusBars_Resize()
	LVBM_StatusBarTimerDrag:SetScale(LVBM.Options.StatusBarSize.Scale);
	LVBM_StatusBarTimerDrag:SetWidth(LVBM.Options.StatusBarSize.Width);
	LVBM_StatusBarTimerDragBar:SetWidth(LVBM.Options.StatusBarSize.Width - 8);
	LVBM_StatusBarTimerDragBarTimer:SetJustifyH("RIGHT");
	LVBM_StatusBarTimerDragBarText:SetWidth(LVBM.Options.StatusBarSize.Width - 59);	
	for i = 1, 10 do
		getglobal("LVBM_StatusBarTimer"..i):SetScale(LVBM.Options.StatusBarSize.Scale);
		getglobal("LVBM_StatusBarTimer"..i):SetWidth(LVBM.Options.StatusBarSize.Width);
		getglobal("LVBM_StatusBarTimer"..i.."Bar"):SetWidth(LVBM.Options.StatusBarSize.Width - 8);
		getglobal("LVBM_StatusBarTimer"..i.."BarTimer"):SetJustifyH("RIGHT");
		getglobal("LVBM_StatusBarTimer"..i.."BarText"):SetWidth(LVBM.Options.StatusBarSize.Width - 59);		
	end
end