local M = {}

local gfxFrameTick = 0
local Toggled = false
--local Toggled2 = false
local Locked = false


local function updateGFX(dt)
	--smokestuff
	--toplel = electrics.values['throttle']
	--if(gfxFrameTick < toplel*2+1.1) then
	--	obj:addParticleByNodesRelative(ex1, ex4, -(toplel+1)*5, 7, 0, toplel+1)
	--end
	if gfxFrameTick > 7 then
		gfxFrameTick = 0
	end
	gfxFrameTick = gfxFrameTick + 1
	--difflock
	if input.keys['T'] then
		if not Toggled then
			Toggled = true
			Locked = not Locked
			drivetrain.toggleDifferentialMode()
			if drivetrain.differentialMode == 0 then
				gui.message("Open differential")
				electrics.values[diff] = 1
			else
				gui.message("Locked differential")
				electrics.values[diff] = 0
			end
		end
	else
		Toggled = false
	end


end

local function onInit()
	--if drivetrain.differentialMode == 0 then
	--	gui.message("Open differential")
	--	electrics.values['diff'] = 1
	--else
	--	gui.message("Locked differential")
	--	electrics.values['diff'] = 0
	--end
	cc = false
	for k, node in pairs (v.data.nodes) do
		if node.name == "ex1" then
			ex1 = k
		end
		if node.name == "ex4" then ex4 = k  end
	end
end

local function resetdifferential()
	originalmode = drivetrain.differentialMode
	drivetrain.toggleDifferentialMode()
	while originalmode ~= drivetrain.differentialMode do
		drivetrain.toggleDifferentialMode()
	end
end

local function onReset()
	resetdifferential()
	onInit()
end

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

return M
