cover_water_injection = createGlobalPropertyf("ksgy/L410/cover_water_injection")
cover_drymotor = createGlobalPropertyf("ksgy/L410/cover_drymotor")
cover_starter = createGlobalPropertyf("ksgy/L410/cover_starter")
cover_man_feater = createGlobalPropertyf("ksgy/L410/cover_man_feater")
light_taxilanding = createGlobalPropertyf("ksgy/L410/light_taxilanding")
light_taxilanding_switch = createGlobalPropertyf("ksgy/L410/light_taxilanding_switch")
cover_fuse = createGlobalPropertyf("ksgy/L410/cover_fuse")

landing_lights_on = globalPropertyi("sim/cockpit2/switches/landing_lights_on")
taxi_light_on = globalPropertyi("sim/cockpit2/switches/taxi_light_on")

set(cover_water_injection, 0)
set(cover_drymotor, 0)
set(cover_starter, 0)
set(cover_man_feater, 0)
set(cover_fuse, 0)
set(light_taxilanding, 0.5)
set(light_taxilanding_switch, 0.5)

local old_taxilanding = 0.5

function goTaxiLightsCallback(phase)
	if phase == 0 then
		local tl = get(light_taxilanding)
		if tl < 0.7 then
			set(light_taxilanding, tl + 0.5)	
		end
	end
	return 0
end

function goLandingLightsCallback(phase)
	if phase == 0 then
		local tl = get(light_taxilanding)
		if get(light_taxilanding) > 0.3 then
			set(light_taxilanding, get(light_taxilanding) - 0.5)
		end
	end
	return 0
end

function update()
	
	if get(light_taxilanding) ~= old_taxilanding then
		if get(light_taxilanding) >= 0 and get(light_taxilanding) <= 0.2 then
			-- landing
			set(taxi_light_on, 1)
			set(landing_lights_on, 1)
			set(light_taxilanding_switch, 0)
		end

		if get(light_taxilanding) > 0.2 and get(light_taxilanding) <= 0.8 then
			-- off
			set(taxi_light_on, 0)
			set(landing_lights_on, 0)
			set(light_taxilanding_switch, 0.5)
		end

		if get(light_taxilanding) > 0.8 then
			-- taxi
			set(taxi_light_on, 1)
			set(landing_lights_on, 0)
			set(light_taxilanding_switch, 1)
		end
		old_taxilanding = get(light_taxilanding)
	end
end

registerCommandHandler(findCommand("sim/lights/taxi_lights_toggle"), 1, goTaxiLightsCallback)
registerCommandHandler(findCommand("sim/lights/landing_lights_toggle"), 1, goLandingLightsCallback)