SC_actionStart = nil;
local SC_oldUseAction = nil;
SC_actionLag = nil;
SC_actionduration = nil;

function SuperCast_OnLoad()
	this:RegisterEvent("UNIT_SPELLCAST_START");
	this:RegisterEvent("ACTIONBAR_UPDATE_COOLDOWN");
end

function SuperCast_OnEvent(event)
	if (event == "UNIT_SPELLCAST_START") then
		if (arg1 ~= "player") then
			return
		end
		
		_, _, _, _, start, end1 = UnitCastingInfo(arg1);
		SC_actionduration = (end1 - start) / 1000;
		
        -- make sure we got the actionbar_update_cooldown
        if (SC_actionStart ~= nil) then
		    SC_actionLag = GetTime() - SC_actionStart;
		    if (SC_actionLag / SC_actionduration) < 1 then
			    SCBarFrame:SetWidth( SC_actionLag / SC_actionduration* eCastingBarStatusBar:GetWidth());

				    SCBarTexture:SetHeight( eCastingBarStatusBar:GetHeight());
				    SCBarFrame:SetHeight  ( eCastingBarStatusBar:GetHeight());
                    -- put the overlay on top of the castbar
				    SCBarFrame:SetFrameLevel(eCastingBarStatusBar:GetFrameLevel()+1);
		    end
        end
	elseif (event == "ACTIONBAR_UPDATE_COOLDOWN") then
		SC_actionStart = GetTime();
	end
end
