local M = {}		--cody by Inn0centJok3r +added shit by jsze xd
local timer = 0
local timer2 = 0
local timer3 = 0
local cycleComplete = 0
local cycleStarting = 0

local function onInit()
	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_L_15"] = 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
    electrics.values["signal_R_15"] = 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
end

local function onReset()
	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_L_15"] = 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
    electrics.values["signal_R_15"] = 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
end

local function updateGFX(dt) 
  if electrics.values["signal_L"] == 1 then
	timer = timer + dt
	
	if timer >= 0.01 then
	electrics.values["signal_L_2"] = 1
	end
	if timer >= 0.0272 then
	electrics.values["signal_L_3"] = 1
	end
	if timer >= 0.0541 then
	electrics.values["signal_L_4"] = 1
	end
	if timer >= 0.081 then
	electrics.values["signal_L_5"] = 1
	end
	if timer >= 0.1079 then
	electrics.values["signal_L_6"] = 1
	end
	if timer >= 0.1348 then
	electrics.values["signal_L_7"] = 1
	end
	if timer >= 0.1617 then
	electrics.values["signal_L_8"] = 1
	end
	if timer >= 0.1886 then
	electrics.values["signal_L_9"] = 1
	end
	if timer >= 0.2155 then
	electrics.values["signal_L_10"] = 1
	end
	if timer >= 0.2424 then
	electrics.values["signal_L_11"] = 1
	end
	if timer >= 0.2693 then
	electrics.values["signal_L_12"] = 1
	end
	if timer >= 0.2962 then
	electrics.values["signal_L_13"] = 1
	end
	if timer >= 0.3231 then
	electrics.values["signal_L_14"] = 1
	end
	if timer >= 0.35 then
	electrics.values["signal_L_15"] = 1
	end
	
  else
	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_L_15"] = 0
	timer = 0	
  end
  
  if electrics.values["signal_R"] == 1 then
	timer2 = timer2 + dt
	
	if timer2 >= 0.01 then
	electrics.values["signal_R_2"] = 1
	end
	if timer2 >= 0.0272 then
	electrics.values["signal_R_3"] = 1
	end
	if timer2 >= 0.0541 then
	electrics.values["signal_R_4"] = 1
	end
	if timer2 >= 0.081 then
	electrics.values["signal_R_5"] = 1
	end
	if timer2 >= 0.1079 then
	electrics.values["signal_R_6"] = 1
	end
	if timer2 >= 0.1348 then
	electrics.values["signal_R_7"] = 1
	end
	if timer2 >= 0.1617 then
	electrics.values["signal_R_8"] = 1
	end
	if timer2 >= 0.1886 then
	electrics.values["signal_R_9"] = 1
	end
	if timer2 >= 0.2155 then
	electrics.values["signal_R_10"] = 1
	end
	if timer2 >= 0.2424 then
	electrics.values["signal_R_11"] = 1
	end
	if timer2 >= 0.2693 then
	electrics.values["signal_R_12"] = 1
	end
	if timer2 >= 0.2962 then
	electrics.values["signal_R_13"] = 1
	end
	if timer2 >= 0.3231 then
	electrics.values["signal_R_14"] = 1
	end
	if timer2 >= 0.35 then
	electrics.values["signal_R_15"] = 1
	end
	
  else
	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
    electrics.values["signal_R_15"] = 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.0714 then
	electrics.values["inno_running_1"] = 1
	end
	if timer3 >= 0.143 then
	electrics.values["inno_running_2"] = 1
	end
	if timer3 >= 0.214 then
	electrics.values["inno_running_3"] = 1
	end
	if timer3 >= 0.286 then
	electrics.values["inno_running_4"] = 1
	end
	if timer3 >= 0.357 then
	electrics.values["inno_running_5"] = 1
	end
	if timer3 >= 0.428 then
	electrics.values["inno_running_6"] = 1
	end
	if timer3 >= 0.5 then
	electrics.values["inno_running_7"] = 1
	end
	if timer3 >= 0.571 then
	electrics.values["inno_running_8"] = 1
	end
	if timer3 >= 0.643 then
	electrics.values["inno_running_9"] = 1
	end
	if timer3 >= 0.714 then
	electrics.values["inno_running_10"] = 1
	end
	if timer3 >= 0.785 then
	electrics.values["inno_running_11"] = 1
	end
	if timer3 >= 0.857 then
	electrics.values["inno_running_12"] = 1
	end
	if timer3 >= 0.928 then
	electrics.values["inno_running_13"] = 1
	end
	if timer3 >= 0.999 then
	electrics.values["inno_running_14"] = 1
	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
  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
  end
end

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

return M