local M = {}		--by xNME
local timer = 0
local timer2 = 0
local timer3 = 0
local cycleComplete = 0
local cycleStarting = 0

local function onInit()
    electrics.values["signal_L_1"] = 0
    electrics.values["signal_L_2"] = 0
    electrics.values["signal_L_3"] = 0
    electrics.values["signal_L_4"] = 0
    electrics.values["signal_L_5"] = 0
    electrics.values["signal_L_6"] = 0
    electrics.values["signal_L_7"] = 0
    electrics.values["signal_L_8"] = 0
    electrics.values["signal_L_9"] = 0
    electrics.values["signal_L_10"] = 0
    electrics.values["signal_L_11"] = 0
    electrics.values["signal_L_12"] = 0
    electrics.values["signal_L_13"] = 0
    electrics.values["signal_L_14"] = 0
	
	electrics.values["signal_R_1"] = 0
    electrics.values["signal_R_2"] = 0
    electrics.values["signal_R_3"] = 0
    electrics.values["signal_R_4"] = 0
    electrics.values["signal_R_5"] = 0
    electrics.values["signal_R_6"] = 0
    electrics.values["signal_R_7"] = 0
    electrics.values["signal_R_8"] = 0
    electrics.values["signal_R_9"] = 0
    electrics.values["signal_R_10"] = 0
    electrics.values["signal_R_11"] = 0
    electrics.values["signal_R_12"] = 0
    electrics.values["signal_R_13"] = 0
    electrics.values["signal_R_14"] = 0
	timer2 = 0
	timer = 0
	timer3 = 0
	cycleStarting = 0
	cycleComplete = 0
--Running light starting sequence
    electrics.values["inno_running_1"] = 1
	electrics.values["inno_running_2"] = 1
    electrics.values["inno_running_3"] = 1
    electrics.values["inno_running_4"] = 1
    electrics.values["inno_running_5"] = 1
    electrics.values["inno_running_6"] = 1
    electrics.values["inno_running_7"] = 1
    electrics.values["inno_running_8"] = 1
    electrics.values["inno_running_9"] = 1
    electrics.values["inno_running_10"] = 1
    electrics.values["inno_running_11"] = 1
    electrics.values["inno_running_12"] = 1
    electrics.values["inno_running_13"] = 1
    electrics.values["inno_running_14"] = 1
	electrics.values["inno_running_15"] = 1
	electrics.values["inno_running_16"] = 1
    electrics.values["inno_running_17"] = 1
	electrics.values["inno_running_18"] = 1
	electrics.values["inno_running_19"] = 1
	electrics.values["inno_running_20"] = 1
	electrics.values["inno_running_21"] = 1
	electrics.values["inno_running_22"] = 1
	electrics.values["inno_running_23"] = 1
	electrics.values["inno_running_24"] = 1
	electrics.values["inno_running_25"] = 1
	electrics.values["inno_running_26"] = 1
	electrics.values["inno_running_27"] = 1
	electrics.values["inno_running_28"] = 1
	electrics.values["inno_running_29"] = 1
	electrics.values["inno_running_30"] = 1
end

local function onReset()
	electrics.values["signal_L_1"] = 0
    electrics.values["signal_L_2"] = 0
    electrics.values["signal_L_3"] = 0
    electrics.values["signal_L_4"] = 0
    electrics.values["signal_L_5"] = 0
    electrics.values["signal_L_6"] = 0
    electrics.values["signal_L_7"] = 0
    electrics.values["signal_L_8"] = 0
    electrics.values["signal_L_9"] = 0
    electrics.values["signal_L_10"] = 0
    electrics.values["signal_L_11"] = 0
    electrics.values["signal_L_12"] = 0
    electrics.values["signal_L_13"] = 0
    electrics.values["signal_L_14"] = 0
	
	electrics.values["signal_R_1"] = 0
    electrics.values["signal_R_2"] = 0
    electrics.values["signal_R_3"] = 0
    electrics.values["signal_R_4"] = 0
    electrics.values["signal_R_5"] = 0
    electrics.values["signal_R_6"] = 0
    electrics.values["signal_R_7"] = 0
    electrics.values["signal_R_8"] = 0
    electrics.values["signal_R_9"] = 0
    electrics.values["signal_R_10"] = 0
    electrics.values["signal_R_11"] = 0
    electrics.values["signal_R_12"] = 0
    electrics.values["signal_R_13"] = 0
    electrics.values["signal_R_14"] = 0
	timer2 = 0
	timer = 0
	timer3 = 0
	cycleStarting = 0
	cycleComplete = 0
--Running light starting sequence
    electrics.values["inno_running_1"] = 1
	electrics.values["inno_running_2"] = 1
    electrics.values["inno_running_3"] = 1
    electrics.values["inno_running_4"] = 1
    electrics.values["inno_running_5"] = 1
    electrics.values["inno_running_6"] = 1
    electrics.values["inno_running_7"] = 1
    electrics.values["inno_running_8"] = 1
    electrics.values["inno_running_9"] = 1
    electrics.values["inno_running_10"] = 1
    electrics.values["inno_running_11"] = 1
    electrics.values["inno_running_12"] = 1
    electrics.values["inno_running_13"] = 1
    electrics.values["inno_running_14"] = 1
	electrics.values["inno_running_15"] = 1
	electrics.values["inno_running_16"] = 1
    electrics.values["inno_running_17"] = 1
	electrics.values["inno_running_18"] = 1
	electrics.values["inno_running_19"] = 1
	electrics.values["inno_running_20"] = 1
	electrics.values["inno_running_21"] = 1
	electrics.values["inno_running_22"] = 1
	electrics.values["inno_running_23"] = 1
	electrics.values["inno_running_24"] = 1
	electrics.values["inno_running_25"] = 1
	electrics.values["inno_running_26"] = 1
	electrics.values["inno_running_27"] = 1
	electrics.values["inno_running_28"] = 1
	electrics.values["inno_running_29"] = 1
	electrics.values["inno_running_30"] = 1
end

local function updateGFX(dt) 
  if electrics.values["signal_L"] == 1 then
	timer = timer + dt
	
	if timer >= 0.01 then
	electrics.values["signal_L_1"] = 1
	end
	if timer >= 0.0272 then
	electrics.values["signal_L_2"] = 1
	end
	if timer >= 0.0541 then
	electrics.values["signal_L_3"] = 1
	end
	if timer >= 0.081 then
	electrics.values["signal_L_4"] = 1
	end
	if timer >= 0.1079 then
	electrics.values["signal_L_5"] = 1
	end
	if timer >= 0.1348 then
	electrics.values["signal_L_6"] = 1
	end
	if timer >= 0.1617 then
	electrics.values["signal_L_7"] = 1
	end
	if timer >= 0.1886 then
	electrics.values["signal_L_8"] = 1
	end
	if timer >= 0.2155 then
	electrics.values["signal_L_9"] = 1
	end
	if timer >= 0.2424 then
	electrics.values["signal_L_10"] = 1
	end
	if timer >= 0.2693 then
	electrics.values["signal_L_11"] = 1
	end
	if timer >= 0.2962 then
	electrics.values["signal_L_12"] = 1
	end
	if timer >= 0.3231 then
	electrics.values["signal_L_13"] = 1
	end
	if timer >= 0.35 then
	electrics.values["signal_L_14"] = 1
	end
	
  else
	electrics.values["signal_L_1"] = 0
    electrics.values["signal_L_2"] = 0
    electrics.values["signal_L_3"] = 0
    electrics.values["signal_L_4"] = 0
    electrics.values["signal_L_5"] = 0
    electrics.values["signal_L_6"] = 0
    electrics.values["signal_L_7"] = 0
    electrics.values["signal_L_8"] = 0
    electrics.values["signal_L_9"] = 0
    electrics.values["signal_L_10"] = 0
    electrics.values["signal_L_11"] = 0
    electrics.values["signal_L_12"] = 0
    electrics.values["signal_L_13"] = 0
    electrics.values["signal_L_14"] = 0
	timer = 0	
  end
  
  if electrics.values["signal_R"] == 1 then
	timer2 = timer2 + dt
	
	if timer2 >= 0.01 then
	electrics.values["signal_R_1"] = 1
	end
	if timer2 >= 0.0272 then
	electrics.values["signal_R_2"] = 1
	end
	if timer2 >= 0.0541 then
	electrics.values["signal_R_3"] = 1
	end
	if timer2 >= 0.081 then
	electrics.values["signal_R_4"] = 1
	end
	if timer2 >= 0.1079 then
	electrics.values["signal_R_5"] = 1
	end
	if timer2 >= 0.1348 then
	electrics.values["signal_R_6"] = 1
	end
	if timer2 >= 0.1617 then
	electrics.values["signal_R_7"] = 1
	end
	if timer2 >= 0.1886 then
	electrics.values["signal_R_8"] = 1
	end
	if timer2 >= 0.2155 then
	electrics.values["signal_R_9"] = 1
	end
	if timer2 >= 0.2424 then
	electrics.values["signal_R_10"] = 1
	end
	if timer2 >= 0.2693 then
	electrics.values["signal_R_11"] = 1
	end
	if timer2 >= 0.2962 then
	electrics.values["signal_R_12"] = 1
	end
	if timer2 >= 0.3231 then
	electrics.values["signal_R_13"] = 1
	end
	if timer2 >= 0.35 then
	electrics.values["signal_R_14"] = 1
	end
	
  else
	electrics.values["signal_R_1"] = 0
    electrics.values["signal_R_2"] = 0
    electrics.values["signal_R_3"] = 0
    electrics.values["signal_R_4"] = 0
    electrics.values["signal_R_5"] = 0
    electrics.values["signal_R_6"] = 0
    electrics.values["signal_R_7"] = 0
    electrics.values["signal_R_8"] = 0
    electrics.values["signal_R_9"] = 0
    electrics.values["signal_R_10"] = 0
    electrics.values["signal_R_11"] = 0
    electrics.values["signal_R_12"] = 0
    electrics.values["signal_R_13"] = 0
    electrics.values["signal_R_14"] = 0
	timer2 = 0	
  end
  
 --Startup sequence for running lights
  if electrics.values["engineRunning"] == 0 and cycleStarting == 0 then
	cycleStarting = 1
	cycleComplete = 0
  elseif electrics.values["engineRunning"] == 1 and cycleStarting == 1 then
	timer3 = timer3 + dt
	
	if timer3 >= 0.01 then
	electrics.values["inno_running_1"] = 1
	end
	if timer3 >= 0.10 then
	electrics.values["inno_running_2"] = 1
	end
	if timer3 >= 0.15 then
	electrics.values["inno_running_1"] = 0
	end
	if timer3 >= 0.20 then
	electrics.values["inno_running_2"] = 0
	end
	if timer3 >= 0.25 then
	electrics.values["inno_running_3"] = 1
	end
	if timer3 >= 0.30 then
	electrics.values["inno_running_4"] = 1
	end
	if timer3 >= 0.35 then
	electrics.values["inno_running_3"] = 0
	end
	if timer3 >= 0.40 then
	electrics.values["inno_running_4"] = 0
	end
	if timer3 >= 0.45 then
	electrics.values["inno_running_5"] = 1
	end
	if timer3 >= 0.50 then
	electrics.values["inno_running_6"] = 1
	end
	if timer3 >= 0.55 then
	electrics.values["inno_running_5"] = 0
	end
	if timer3 >= 0.60 then
	electrics.values["inno_running_6"] = 0
	end
	if timer3 >= 0.65 then
	electrics.values["inno_running_7"] = 1
	end
	if timer3 >= 0.70 then
	electrics.values["inno_running_8"] = 1
	end
	if timer3 >= 0.75 then
	electrics.values["inno_running_7"] = 0
	end
	if timer3 >= 0.80 then
	electrics.values["inno_running_8"] = 0
	end
	if timer3 >= 0.85 then
	electrics.values["inno_running_9"] = 1
	end
	if timer3 >= 0.90 then
	electrics.values["inno_running_10"] = 1
	end
	if timer3 >= 0.95 then
	electrics.values["inno_running_9"] = 0
	end
	if timer3 >= 1.00 then
	electrics.values["inno_running_10"] = 0
	end
	if timer3 >= 1.05 then
	electrics.values["inno_running_11"] = 1
	end
	if timer3 >= 1.10 then
	electrics.values["inno_running_12"] = 1
	end
	if timer3 >= 1.15 then
	electrics.values["inno_running_11"] = 0
	end
	if timer3 >= 1.20 then
	electrics.values["inno_running_12"] = 0
	end
	if timer3 >= 1.25 then
	electrics.values["inno_running_13"] = 1
	end
	if timer3 >= 1.30 then
	electrics.values["inno_running_14"] = 1
	end
	if timer3 >= 1.35 then
	electrics.values["inno_running_13"] = 0
	end
	if timer3 >= 1.40 then
	electrics.values["inno_running_14"] = 0
	end
	if timer3 >= 1.45 then
	electrics.values["inno_running_15"] = 1
	end
	if timer3 >= 1.50 then
	electrics.values["inno_running_16"] = 1
	end
	if timer3 >= 1.55 then
	electrics.values["inno_running_15"] = 0
	end
	if timer3 >= 1.60 then
	electrics.values["inno_running_16"] = 0
	end
	if timer3 >= 1.65 then
	electrics.values["inno_running_17"] = 1
	end
	if timer3 >= 1.70 then
	electrics.values["inno_running_18"] = 1
	end
	if timer3 >= 1.75 then
	electrics.values["inno_running_17"] = 0
	end
	if timer3 >= 1.80 then
	electrics.values["inno_running_18"] = 0
	end
	if timer3 >= 1.85 then
	electrics.values["inno_running_19"] = 1
	end
	if timer3 >= 1.90 then
	electrics.values["inno_running_20"] = 1
	end
	if timer3 >= 1.95 then
	electrics.values["inno_running_19"] = 0
	end
	if timer3 >= 2.00 then
	electrics.values["inno_running_20"] = 0
	end
	if timer3 >= 2.05 then
	electrics.values["inno_running_21"] = 1
	end
	if timer3 >= 2.10 then
	electrics.values["inno_running_22"] = 1
	end
	if timer3 >= 2.15 then
	electrics.values["inno_running_21"] = 0
	end
	if timer3 >= 2.20 then
	electrics.values["inno_running_22"] = 0
	end
	if timer3 >= 2.25 then
	electrics.values["inno_running_23"] = 1
	end
	if timer3 >= 2.30 then
	electrics.values["inno_running_24"] = 1
	end
	if timer3 >= 2.35 then
	electrics.values["inno_running_23"] = 0
	end
	if timer3 >= 2.40 then
	electrics.values["inno_running_24"] = 0
	end
	if timer3 >= 2.45 then
	electrics.values["inno_running_25"] = 1
	end
	if timer3 >= 2.50 then
	electrics.values["inno_running_26"] = 1
	end
	if timer3 >= 2.55 then
	electrics.values["inno_running_25"] = 0
	end
	if timer3 >= 2.60 then
	electrics.values["inno_running_26"] = 0
	end
	if timer3 >= 2.65 then
	electrics.values["inno_running_27"] = 1
	end
	if timer3 >= 2.70 then
	electrics.values["inno_running_28"] = 1
	end
	if timer3 >= 2.75 then
	electrics.values["inno_running_27"] = 0
	end
	if timer3 >= 2.80 then
	electrics.values["inno_running_28"] = 0
	end
	if timer3 >= 2.85 then
	electrics.values["inno_running_29"] = 1
	end
	if timer3 >= 2.90 then
	electrics.values["inno_running_30"] = 1
	end
	if timer3 >= 2.95 then
	electrics.values["inno_running_29"] = 0
	end
	if timer3 >= 3.00 then
	electrics.values["inno_running_30"] = 0
	cycleStarting = 0
	timer3 = 0
	cycleComplete = 1
	end
  end
  if electrics.values["engineRunning"] == 1 and cycleComplete == 1 then
    electrics.values["inno_running_1"] = 1
	electrics.values["inno_running_2"] = 1
    electrics.values["inno_running_3"] = 1
    electrics.values["inno_running_4"] = 1
    electrics.values["inno_running_5"] = 1
    electrics.values["inno_running_6"] = 1
    electrics.values["inno_running_7"] = 1
    electrics.values["inno_running_8"] = 1
    electrics.values["inno_running_9"] = 1
    electrics.values["inno_running_10"] = 1
    electrics.values["inno_running_11"] = 1
    electrics.values["inno_running_12"] = 1
    electrics.values["inno_running_13"] = 1
    electrics.values["inno_running_14"] = 1
	electrics.values["inno_running_15"] = 1
	electrics.values["inno_running_16"] = 1
    electrics.values["inno_running_17"] = 1
	electrics.values["inno_running_18"] = 1
	electrics.values["inno_running_19"] = 1
	electrics.values["inno_running_20"] = 1
	electrics.values["inno_running_21"] = 1
	electrics.values["inno_running_22"] = 1
	electrics.values["inno_running_23"] = 1
	electrics.values["inno_running_24"] = 1
	electrics.values["inno_running_25"] = 1
	electrics.values["inno_running_26"] = 1
	electrics.values["inno_running_27"] = 1
	electrics.values["inno_running_28"] = 1
	electrics.values["inno_running_29"] = 1
	electrics.values["inno_running_30"] = 1
	
  elseif electrics.values["engineRunning"] == 0 and cycleComplete == 0 then
    electrics.values["inno_running_1"] = 0
	electrics.values["inno_running_2"] = 0
    electrics.values["inno_running_3"] = 0
    electrics.values["inno_running_4"] = 0
    electrics.values["inno_running_5"] = 0
    electrics.values["inno_running_6"] = 0
    electrics.values["inno_running_7"] = 0
    electrics.values["inno_running_8"] = 0
    electrics.values["inno_running_9"] = 0
    electrics.values["inno_running_10"] = 0
    electrics.values["inno_running_11"] = 0
    electrics.values["inno_running_12"] = 0
    electrics.values["inno_running_13"] = 0
    electrics.values["inno_running_14"] = 0
	electrics.values["inno_running_15"] = 0
	electrics.values["inno_running_16"] = 0
    electrics.values["inno_running_17"] = 0
	electrics.values["inno_running_18"] = 0
	electrics.values["inno_running_19"] = 0
	electrics.values["inno_running_20"] = 0
	electrics.values["inno_running_21"] = 0
	electrics.values["inno_running_22"] = 0
	electrics.values["inno_running_23"] = 0
	electrics.values["inno_running_24"] = 0
	electrics.values["inno_running_25"] = 0
	electrics.values["inno_running_26"] = 0
	electrics.values["inno_running_27"] = 0
	electrics.values["inno_running_28"] = 0
	electrics.values["inno_running_29"] = 0
	electrics.values["inno_running_30"] = 0
  end
end

-- public interface
M.onInit = onInit
M.onReset = onReset
M.updateGFX = updateGFX

return M