function init()
	door = FindShape("door")
	motor = FindJoint("motor")
	sensor = FindTrigger("sensor")
	sound = LoadSound("MOD/sound/museum-door0")
	
	min, max = GetJointLimits(motor)
	doorType = GetIntParam("type", 0) -- 0 = Automatic, 1 = Manual, 2 = Locked
	strength = GetFloatParam("strength", 500)
	elevator= GetStringParam("elevator", "")
	elevatorTimeout = 0
	indicatorLightIntensity = 1
	if elevator ~= "" then
		elevatorBody = FindBody(elevator,true)
		doorType = 4
	end
	manualstrenght = GetFloatParam("manualstrength", 250)
	
	isOpen = false
end

function tick(dt)
	local newIsOpen = false
			
	-- Automatic door
	if doorType == 0 then
		if IsPointInTrigger(sensor, GetPlayerPos()) then
			newIsOpen = true
			SetJointMotorTarget(motor, max, 3.5, strength)
			SetValue("indicatorLightIntensity", 0, "linear", 0.1)
		else
			SetJointMotorTarget(motor, min, 3.5, strength)
			SetValue("indicatorLightIntensity", 0.5, "easein", 0.1)
		end
	end
	
	-- Manual door
	if doorType == 1 then
		SetJointMotorTarget(motor, min, 3.5, manualstrenght)
	end
	
	-- Locked door
	if doorType == 2 then
		SetJointMotorTarget(motor, min, 5)
	end

	-- Open once
	if doorType == 3 then
		if IsPointInTrigger(sensor, GetPlayerPos()) then
			opened = true
		end
		if opened then
			newIsOpen = true
			SetJointMotorTarget(motor, max, 3.5, strength)
			SetValue("indicatorLightIntensity", 0, "linear", 0.1)
		else
			SetJointMotorTarget(motor, min, 3.5, strength)
		end
	end
	
	if newIsOpen ~= isOpen then
		PlaySound(sound, GetShapeWorldTransform(door).pos)
	end
	isOpen = newIsOpen
end