WindInfo_CurrHealth = 0;
WindInfo_CurrMana = 0;

function WindInfoTick_OnLoad()
	this.update = 0;
	this.alphamana = 1;
	this.alphahealth = 1;
	this:RegisterEvent("UNIT_HEALTH");
	this:RegisterEvent("UNIT_MAXHEALTH");
	this:RegisterEvent("UNIT_MANA");
	this:RegisterEvent("UNIT_MAXMANA");
	this:RegisterEvent("VARIABLES_LOADED");
	WindInfoTicksHealthText:SetText("|cFFFFFF00 HP : |c00FFFFFF" .. "0" .. "|r");
	WindInfoTicksManaText:SetText("|cFFFFFF00 MP : |c00FFFFFF" .. "0" .. "|r");
end

function WindInfoTick_OnEvent(event)
	if ( event == "VARIABLES_LOADED" ) then
		WindInfoTick_initConfig();
		WindInfoTick_setPoint();
		WindInfoTick_setScale();
		WindInfoTick_setSize();
		WindInfoTick_setView();
		WindInfoTick_setMouse();
	end
	if ( event == "UNIT_HEALTH" or event == "UNIT_MAXHEALTH" and arg1 == "player" ) then
		local curr = UnitHealth("player");
		if ( curr > WindInfo_CurrHealth and WindInfo_CurrHealth ~= 0 ) then
			WindInfoTicksHealthText:SetText("|cFFFFFF00 HP : |c00FFFFFF" .. curr-WindInfo_CurrHealth .. "|r");
			WindInfoTick_LastHP = curr-WindInfo_CurrHealth;
			WindInfoTick.alphahealth = 1;
			WindInfoTicksHealthText:SetAlpha(1);
		end
		WindInfo_CurrHealth = curr;
	end
	if ( event == "UNIT_MANA" or event == "UNIT_MAXMANA" and arg1 == "player" ) then
		local curr = UnitMana("player");
		if ( curr > WindInfo_CurrMana and WindInfo_CurrMana ~= 0 ) then
			WindInfoTicksManaText:SetText("|cFFFFFF00 MP : |c00FFFFFF" .. curr-WindInfo_CurrMana .. "|r");
			WindInfoTick_LastMP = curr-WindInfo_CurrMana;
			WindInfoTick.alphamana = 1;
			WindInfoTicksManaText:SetAlpha(1);
		end
		WindInfo_CurrMana = curr;
	end
end

function WindInfoTick_FadeMana()
	local class, eClass = UnitClass("player");
	if ( UnitPowerType("player") > 0 and eClass ~= "DRUID" ) then
		WindInfoTicksHealthText:SetJustifyH("CENTER");
		WindInfoTicksManaText:SetAlpha(0);
	else
		if ( this.alphamana <= 0.5 ) then return; end
		this.alphamana = this.alphamana - 0.0075;
		WindInfoTicksManaText:SetAlpha(this.alphamana);
	end
end

function WindInfoTick_FadeHealth()
	if ( this.alphahealth <= 0.5 ) then return; end
	this.alphahealth = this.alphahealth - 0.0075;
	WindInfoTicksHealthText:SetAlpha(this.alphahealth);
end

function WindInfoTick_Fade(elapsed)
	if (not IsAddOnLoaded("WindConfig")) then
		this.update = this.update + elapsed;
		if ( this.update >= 0.01 ) then
			this.update = this.update - 0.01;
			WindInfoTick_FadeMana();
			WindInfoTick_FadeHealth();
		end
	end
end

function WindInfoTick_initConfig()
	if (not WindInfoTickConfig) then WindInfoTickConfig = WindInfoDefault["Tick"]; end
end

function WindInfoTick_setPoint()
	WindCommon_setPoint(WindInfoTick, WindInfoTickConfig[1], "WindInfo", WindInfoTickConfig[1], WindInfoTickConfig[2], WindInfoTickConfig[3]);
end

function WindInfoTick_setScale()
	WindInfoTick:SetScale(WindInfoTickConfig[4]);
end

function WindInfoTick_setSize()
	WindCommon_setSize(WindInfoTick, WindInfoTickConfig[5], WindInfoTickConfig[6]);
end

function WindInfoTick_setView()
	if (WindInfoTickConfig[7]) then WindInfoTick:Show();
	else WindInfoTick:Hide(); end
end

function WindInfoTick_setMouse()
	if (WindInfoTickConfig[8]) then WindInfoTick:Show();
	else WindInfoTick:Hide(); end
end