--
-- K7
-- Specialization for K7
--
-- @author  	Aluha74rus
-- @version 	v1.0
-- @date  		02/09/19
--

K7 = {};

function K7.prerequisitesPresent(specializations)
    return 
	SpecializationUtil.hasSpecialization(Motorized, specializations) and 
	SpecializationUtil.hasSpecialization(Enterable, specializations) and 
	SpecializationUtil.hasSpecialization(AnimatedVehicle, specializations) and  
	SpecializationUtil.hasSpecialization(Drivable, specializations);
end;

function K7.registerEventListeners(vehicleType)	
	SpecializationUtil.registerEventListener(vehicleType, "onLoad", K7);
	SpecializationUtil.registerEventListener(vehicleType, "onUpdate", K7)
	SpecializationUtil.registerEventListener(vehicleType, "onUpdateTick", K7)
end

function K7.registerFunctions(vehicleType)
    SpecializationUtil.registerFunction(vehicleType, "playklawishaAnims", K7.playklawishaAnims)
end

function K7:onLoad(savegame)
	
	-- self.podMonitor = I3DUtil.indexToObject(self.components, "0>1|12|1");	
	self.pust = I3DUtil.indexToObject(self.components, "0>1|3|4");	
	self.pust1 = I3DUtil.indexToObject(self.components, "0>1|3|8|0|1");	
	-- self.pust2 = I3DUtil.indexToObject(self.components, "0>3|27|0|9");	
	-- self.pust3 = I3DUtil.indexToObject(self.components, "0>3|27|0|10");		
	self.pust4 = I3DUtil.indexToObject(self.components, "0>1|1|2|12");	
	
	-- self.oneSD = I3DUtil.indexToObject(self.components, "0>3|27|0|0");
	self.oneSD1 = I3DUtil.indexToObject(self.components, "0>1|1|3|3");
	-- self.twoSD = I3DUtil.indexToObject(self.components, "0>3|27|0|1");
	-- self.twoSD1 = I3DUtil.indexToObject(self.components, "0>3|27|0|1");
	-- self.threeSD = I3DUtil.indexToObject(self.components, "0>3|27|0|2");
	self.threeSD1 = I3DUtil.indexToObject(self.components, "0>1|1|3|2");
	-- self.fourSD = I3DUtil.indexToObject(self.components, "0>3|27|0|3");	
	-- self.fourSD1 = I3DUtil.indexToObject(self.components, "0>3|27|0|3");	
	-- self.TD = I3DUtil.indexToObject(self.components, "0>3|27|0|7");
	-- self.ND = I3DUtil.indexToObject(self.components, "0>3|27|0|10|0");	
	-- self.HD = I3DUtil.indexToObject(self.components, "0>3|27|0|5");
	-- self.LD = I3DUtil.indexToObject(self.components, "0>3|27|0|6");
	
	self.oneS = I3DUtil.indexToObject(self.components, "0>3|17|7|1");	
	self.twoS = I3DUtil.indexToObject(self.components, "0>3|17|7|2");	
	self.threeS = I3DUtil.indexToObject(self.components, "0>3|17|7|3");	
	self.fourS = I3DUtil.indexToObject(self.components, "0>3|17|7|0");	
	self.T = I3DUtil.indexToObject(self.components, "0>1|3|5");
	self.N = I3DUtil.indexToObject(self.components, "0>1|1|3|1");	
	self.H = I3DUtil.indexToObject(self.components, "0>1|3|8|1|0");
	self.L = I3DUtil.indexToObject(self.components, "0>1|3|8|1|1");
	self.F = I3DUtil.indexToObject(self.components, "0>1|1|3|5");
	self.R = I3DUtil.indexToObject(self.components, "0>1|1|3|7");
	self.FR = I3DUtil.indexToObject(self.components, "0>1|3|8|0|1|0");
	-- self.PodMassa = I3DUtil.indexToObject(self.components, "0>1|1|2|2|0");
	
	-- self.Komp = I3DUtil.indexToObject(self.components, "0>1|1|2|7");
	
    self.KlawishaMassa = getXMLString(self.xmlFile, "vehicle.KlawishaMassa#animationName");
    self.Monitor = getXMLString(self.xmlFile, "vehicle.Monitor#animationName");
    self.Monitor1 = getXMLString(self.xmlFile, "vehicle.MonitorDisp#animationName");
    self.Zagiganie = getXMLString(self.xmlFile, "vehicle.Zagiganie#animationName");
	self.gearShifter = I3DUtil.indexToObject(self.components, getXMLString(self.xmlFile, "vehicle.K7.gearShifter#index"));
	self.klawishaLH = I3DUtil.indexToObject(self.components, getXMLString(self.xmlFile, "vehicle.K7.klawishaLH#index"));
    self.KlawishaFR = I3DUtil.indexToObject(self.components, getXMLString(self.xmlFile, "vehicle.K7.Klawisha#KlawishaFR"));
	self.dd = {}
	self.dd.f = I3DUtil.indexToObject(self.components, getXMLString(self.xmlFile, "vehicle.K7.forward#index"));
	self.dd.fa = false;
	self.dd.b = I3DUtil.indexToObject(self.components, getXMLString(self.xmlFile, "vehicle.K7.backward#index"));
	self.dd.ba = false;
	-- setVisibility( self.dd.f, false );
	-- setVisibility( self.dd.b, false );	
	
    self.speedWaitingMaxTimeMonitor = 2500; 
	self.speedWaitingTimerMonitor = 1; 
	self.monitorFirst  = I3DUtil.indexToObject(self.components, getXMLString(self.xmlFile, "vehicle.K7.monitorImage#firstIndex"));
	self.monitorSecond = I3DUtil.indexToObject(self.components, getXMLString(self.xmlFile, "vehicle.K7.monitorImage#secondIndex"));
	self.monitorThird  = I3DUtil.indexToObject(self.components, getXMLString(self.xmlFile, "vehicle.K7.monitorImage#thirdIndex"));
	
    local blinkerhebelNode = I3DUtil.indexToObject(self.components, getXMLString(self.xmlFile, "vehicle.K7.Poworotniki#index"));
    if blinkerhebelNode ~= nil then
        self.blinkerhebel = {};
        self.blinkerhebel.node = blinkerhebelNode;
        local x, y, z = StringUtil.getVectorFromString(getXMLString(self.xmlFile, "vehicle.K7.Poworotniki#minRot"));
        self.blinkerhebel.minRot = {};
        self.blinkerhebel.minRot[1] = MathUtil.degToRad(Utils.getNoNil(x, 0));
        self.blinkerhebel.minRot[2] = MathUtil.degToRad(Utils.getNoNil(y, 0));
        self.blinkerhebel.minRot[3] = MathUtil.degToRad(Utils.getNoNil(z, 0));

        local x, y, z = StringUtil.getVectorFromString(getXMLString(self.xmlFile, "vehicle.K7.Poworotniki#rotLeft"));
        self.blinkerhebel.leftRot = {};
        self.blinkerhebel.leftRot[1] = MathUtil.degToRad(Utils.getNoNil(x, 0));
        self.blinkerhebel.leftRot[2] = MathUtil.degToRad(Utils.getNoNil(y, 0));
        self.blinkerhebel.leftRot[3] = MathUtil.degToRad(Utils.getNoNil(z, 0));

        local x, y, z = StringUtil.getVectorFromString(getXMLString(self.xmlFile, "vehicle.K7.Poworotniki#rotRight"));
        self.blinkerhebel.rightRot = {};
        self.blinkerhebel.rightRot[1] = MathUtil.degToRad(Utils.getNoNil(x, 0));
        self.blinkerhebel.rightRot[2] = MathUtil.degToRad(Utils.getNoNil(y, 0));
        self.blinkerhebel.rightRot[3] = MathUtil.degToRad(Utils.getNoNil(z, 0));

        self.blinkerhebel.rotTime = Utils.getNoNil(getXMLString(self.xmlFile, "vehicle.K7.Poworotniki#rotTime"), 1)*1000;
		self.blinkerhebel.lastDir = 1;
    end;
	self.gidAngle = 0;
	self.gidravlika = I3DUtil.indexToObject(self.components, getXMLString(self.xmlFile, "vehicle.K7.gidRicag#gidravlika"));
	self.gidRicag = {};
	self.gidRicag.node = I3DUtil.indexToObject(self.components, getXMLString(self.xmlFile, "vehicle.K7.gidRicag#index"));
	if self.gidRicag.node ~= nil then
		self.gidRicag.minRot = {MathUtil.degToRad(getXMLFloat(self.xmlFile, "vehicle.K7.gidRicag#minRot"))};
		self.gidRicag.maxRot = {MathUtil.degToRad(getXMLFloat(self.xmlFile, "vehicle.K7.gidRicag#maxRot"))};
		self.gidRicag.Rot = {MathUtil.degToRad(getXMLFloat(self.xmlFile, "vehicle.K7.gidRicag#Rot"))};
		self.gidRicag.rotTime = getXMLFloat(self.xmlFile, "vehicle.K7.gidRicag#rotTime")*1000;
		self.gidRicag.posX = true;
		self.gidRicag.posZ = true;
	end;
    
    local baseString = string.format("vehicle.K7.");
    self.klawishaAnims = {};
    if hasXMLProperty(self.xmlFile, "vehicle.K7.klawishaAnims") then
        
        self.klawishaAnims.lights = {};
        i=0;
        while true do
            self.klawishaAnims.lights[i] = getXMLString(self.xmlFile,baseString..string.format("klawishaAnims.lights#animName%d", i));
            if self.klawishaAnims.lights[i] == nil then
                break;
            end;
            i=i+1;
        end;
    end;
    
end;
function K7:onUpdate(dt)   
    if self.isClient then
        if self.klawishaAnims.lights ~= nil then
            for i=0, self.spec_lights.numLightTypes do 
                if bitAND(self.spec_lights.lightsTypesMask, 2^i) ~= 0 then
                    self:playklawishaAnims(self.klawishaAnims.lights[i], 1);
                else
                    self:playklawishaAnims(self.klawishaAnims.lights[i], -1);
                end;
            end;
        end;
    end;		
	if self.movingDirection > 0 and self.lastSpeed*3600 > 3 and self.dd.fa == false then
		self.dd.fa = true;
        setRotation(self.KlawishaFR, MathUtil.degToRad(7), 0, 0);
		-- setVisibility(self.dd.f, true);
	    setVisibility(self.F, true);
	elseif self.dd.fa == true and (self.lastSpeed*3600 < 3 or self.movingDirection < 0) then
		self.dd.fa = false;
	    setVisibility(self.F, false);
        setRotation(self.KlawishaFR, 0, 0, 0);
		-- setVisibility(self.dd.f, false);	
	end;
	if self.movingDirection < 0 and self.lastSpeed*3600 > 3 and self.dd.ba == false then
		self.dd.ba = true;
        setRotation(self.KlawishaFR, MathUtil.degToRad(-7), 0, 0);
		-- setVisibility(self.dd.b, true);
	    setVisibility(self.R, true);
	elseif self.dd.ba == true and (self.lastSpeed*3600 < 3 or self.movingDirection > 0) then
		self.dd.ba = false;
	    setVisibility(self.R, false);
        setRotation(self.KlawishaFR, 0, 0, 0);
		-- setVisibility(self.dd.b, false);	
	end;
	
    local MonitorEnableTimeStartDelay = 0;
	local MonitorEnableTime = (self.spec_motorized.motorStartTime - self.spec_motorized.motorStartDuration) + MonitorEnableTimeStartDelay;
	local Duration = 2840;
	local DisableTime = MonitorEnableTime + Duration;
	
    local Monitor1EnableTimeStartDelay = 2400;
	local Monitor1EnableTime = (self.spec_motorized.motorStartTime - self.spec_motorized.motorStartDuration) + Monitor1EnableTimeStartDelay;
	local Duration = 300;
	local DisableTime = Monitor1EnableTime + Duration;

    local ZagiganieEnableTimeStartDelay = 750;
	local ZagiganieEnableTime = (self.spec_motorized.motorStartTime - self.spec_motorized.motorStartDuration) + ZagiganieEnableTimeStartDelay;
	local Duration = 2040;
	local DisableTime = ZagiganieEnableTime + Duration;
	
    local KlawishaMassaEnableTimeStartDelay = 200;
	local KlawishaMassaEnableTime = (self.spec_motorized.motorStartTime - self.spec_motorized.motorStartDuration) + KlawishaMassaEnableTimeStartDelay;
	if self.isClient then
		if self.Monitor ~= nil and self.playAnimation ~= nil then
		    if (g_currentMission.time <= DisableTime and g_currentMission.time >= MonitorEnableTime  and self.spec_motorized.isMotorStarted) then
                self:playAnimation(self.Monitor, 1, nil, true);
		    else
                self:playAnimation(self.Monitor, -1, nil, true);
		    end;
		end;
		if self.Monitor1 ~= nil and self.playAnimation ~= nil then
		    if (g_currentMission.time <= DisableTime and g_currentMission.time >= Monitor1EnableTime  and self.spec_motorized.isMotorStarted) then
                self:playAnimation(self.Monitor1, 1, nil, true);
		    else
                self:playAnimation(self.Monitor1, -1, nil, true);
		    end;
		end;
		if self.Zagiganie ~= nil and self.playAnimation ~= nil then
		    if (g_currentMission.time <= DisableTime and g_currentMission.time >= ZagiganieEnableTime  and self.spec_motorized.isMotorStarted) then
                self:playAnimation(self.Zagiganie, 1, nil, true);
		    else
                self:playAnimation(self.Zagiganie, -1, nil, true);
		    end;
		end;
		if self.KlawishaMassa ~= nil and self.playAnimation ~= nil then
		    if (g_currentMission.time <= KlawishaMassaEnableTime  and self.spec_motorized.isMotorStarted) then
                self:playAnimation(self.KlawishaMassa, 1, nil, true);
		    else
                self:playAnimation(self.KlawishaMassa, -1, nil, true);
		    end;
		end;	
	end;
    if self.spec_motorized.isMotorStarted then
	    -- setVisibility(self.PodMassa, true);
	    -- setVisibility(self.Komp, true);
	    -- setVisibility(self.pust, true);
	    -- setVisibility(self.pust1, true);
	    -- setVisibility(self.pust2, true);
	    -- setVisibility(self.pust3, true);
	    -- setVisibility(self.pust4, true);
	    -- setVisibility(self.podMonitor, true);
	else
	    -- setVisibility(self.PodMassa, false);
	    -- setVisibility(self.Komp, false);
	    -- setVisibility(self.pust, false);
	    -- setVisibility(self.pust1, false);
	    -- setVisibility(self.pust2, false);
	    -- setVisibility(self.pust3, false);
	    -- setVisibility(self.pust4, false);
	    -- setVisibility(self.podMonitor, false);
	end;
		
	if self.spec_motorized.isMotorStarted then
	
        local speed = self.lastSpeed*3600;
        if self.gearShifter ~= nil  then
		
            if speed < 0.1 then
                setRotation(self.gearShifter, MathUtil.degToRad(0),   MathUtil.degToRad(0), MathUtil.degToRad(0));
	            setVisibility(self.N, true);
	            setVisibility(self.FR, true);
	            setVisibility(self.T, false);
	            setVisibility(self.oneS, false);
	            setVisibility(self.twoS, false);
	            setVisibility(self.threeS, false);
	            setVisibility(self.fourS, false);
				
	            -- setVisibility(self.ND, true);
	            -- setVisibility(self.TD, false);
	            -- setVisibility(self.oneSD, false);
	            -- setVisibility(self.twoSD, false);
	            -- setVisibility(self.threeSD, false);
	            -- setVisibility(self.fourSD, false);
				
				setVisibility(self.F, false);
				setVisibility(self.oneSD1, false);
				setVisibility(self.threeSD1, false);
				
            else
			if speed >= 0.1 and speed < 8 then
                setRotation(self.gearShifter, MathUtil.degToRad(20), MathUtil.degToRad(0), MathUtil.degToRad(0));
	            setVisibility(self.N, false);
	            setVisibility(self.FR, false);
	            setVisibility(self.T, true);
	            setVisibility(self.oneS, false);
	            setVisibility(self.twoS, false);
	            setVisibility(self.threeS, false);
	            setVisibility(self.fourS, false);				
	            -- setVisibility(self.ND, false);
	            -- setVisibility(self.TD, true);
	            -- setVisibility(self.oneSD, false);
	            -- setVisibility(self.twoSD, false);
	            -- setVisibility(self.threeSD, false);
	            -- setVisibility(self.fourSD, false);

				setVisibility(self.F, true);
				setVisibility(self.oneSD1, true);
				setVisibility(self.threeSD1, false);
				
				

				elseif speed >= 7 and speed < 8 then
                setRotation(self.gearShifter, MathUtil.degToRad(0), MathUtil.degToRad(0), MathUtil.degToRad(20));
	            setVisibility(self.N, false);
	            setVisibility(self.FR, false);
	            setVisibility(self.T, false);
	            setVisibility(self.oneS, true);
	            setVisibility(self.twoS, false);
	            setVisibility(self.threeS, false);
	            setVisibility(self.fourS, false);
				
	            -- setVisibility(self.ND, false);
	            -- setVisibility(self.TD, false);
	            -- setVisibility(self.oneSD, true);
	            -- setVisibility(self.twoSD, false);
	            -- setVisibility(self.threeSD, false);
	            -- setVisibility(self.fourSD, false);

				setVisibility(self.F, true);
				setVisibility(self.oneSD1, true);
				setVisibility(self.threeSD1, false);
				
				
				elseif speed >= 8 and speed < 15 then
                setRotation(self.gearShifter, MathUtil.degToRad(20), MathUtil.degToRad(0), MathUtil.degToRad(0));
	            setVisibility(self.N, false);
	            setVisibility(self.FR, false);
	            setVisibility(self.T, false);
	            setVisibility(self.oneS, true);
	            setVisibility(self.twoS, false);
	            setVisibility(self.threeS, false);
	            setVisibility(self.fourS, false);
				
	            -- setVisibility(self.ND, false);
	            -- setVisibility(self.TD, false);
	            -- setVisibility(self.oneSD, true);
	            -- setVisibility(self.twoSD, false);
	            -- setVisibility(self.threeSD, false);
	            -- setVisibility(self.fourSD, false);
				
				setVisibility(self.F, true);
				setVisibility(self.oneSD1, true);
				setVisibility(self.threeSD1, false);
				
				
            elseif speed >= 15 and speed < 16 then
                setRotation(self.gearShifter, MathUtil.degToRad(20), MathUtil.degToRad(0), MathUtil.degToRad(20));
	            setVisibility(self.N, false);
	            setVisibility(self.FR, false);
	            setVisibility(self.T, false);
	            setVisibility(self.oneS, false);
	            setVisibility(self.twoS, true);
	            setVisibility(self.threeS, false);
	            setVisibility(self.fourS, false);
				
	            -- setVisibility(self.ND, false);
	            -- setVisibility(self.TD, false);
	            -- setVisibility(self.oneSD, false);
	            -- setVisibility(self.twoSD, true);
	            -- setVisibility(self.threeSD, false);
	            -- setVisibility(self.fourSD, false);	

				setVisibility(self.F, true);
				setVisibility(self.oneSD1, true);
				setVisibility(self.threeSD1, false);
				
				
				
				
            elseif speed >= 16 and speed < 22 then
                setRotation(self.gearShifter, MathUtil.degToRad(20), MathUtil.degToRad(0), MathUtil.degToRad(0));
	            setVisibility(self.N, false);
	            setVisibility(self.FR, false);
	            setVisibility(self.T, false);
	            setVisibility(self.oneS, false);
	            setVisibility(self.twoS, true);
	            setVisibility(self.threeS, false);
	            setVisibility(self.fourS, false);
				
	            -- setVisibility(self.ND, false);
	            -- setVisibility(self.TD, false);
	            -- setVisibility(self.oneSD, false);
	            -- setVisibility(self.twoSD, true);
	            -- setVisibility(self.threeSD, false);
	            -- setVisibility(self.fourSD, false);
				
				setVisibility(self.F, true);
				setVisibility(self.oneSD1, true);
				setVisibility(self.threeSD1, false);
				
				
				
			elseif speed >= 22 and speed < 24 then
                setRotation(self.gearShifter, MathUtil.degToRad(20),  MathUtil.degToRad(0), MathUtil.degToRad(20));
	            setVisibility(self.N, false);
	            setVisibility(self.FR, false);
	            setVisibility(self.T, false);
	            setVisibility(self.oneS, false);
	            setVisibility(self.twoS, false);
	            setVisibility(self.threeS, true);
	            setVisibility(self.fourS, false);
				
	            -- setVisibility(self.ND, false);
	            -- setVisibility(self.TD, false);
	            -- setVisibility(self.oneSD, false);
	            -- setVisibility(self.twoSD, false);
	            -- setVisibility(self.threeSD, true);
	            -- setVisibility(self.fourSD, false);	
				
				setVisibility(self.F, true);
				setVisibility(self.oneSD1, true);
				setVisibility(self.threeSD1, false);
				
				
            elseif speed >= 24 and speed < 35 then
                setRotation(self.gearShifter, MathUtil.degToRad(20),  MathUtil.degToRad(0), MathUtil.degToRad(0));
	            setVisibility(self.N, false);
	            setVisibility(self.FR, false);
	            setVisibility(self.T, false);
	            setVisibility(self.oneS, false);
	            setVisibility(self.twoS, false);
	            setVisibility(self.threeS, true);
	            setVisibility(self.fourS, false);
				
	            -- setVisibility(self.ND, false);
	            -- setVisibility(self.TD, false);
	            -- setVisibility(self.oneSD, false);
	            -- setVisibility(self.twoSD, false);
	            -- setVisibility(self.threeSD, true);
	            -- setVisibility(self.fourSD, false);
				
				setVisibility(self.F, true);
				setVisibility(self.oneSD1, false);
				setVisibility(self.threeSD1, true);
				
				
			elseif speed >= 35 and speed < 37 then
                setRotation(self.gearShifter, MathUtil.degToRad(20),  MathUtil.degToRad(0), MathUtil.degToRad(20));
	            setVisibility(self.N, false);
	            setVisibility(self.FR, false);
	            setVisibility(self.T, false);
	            setVisibility(self.oneS, false);
	            setVisibility(self.twoS, false);
	            setVisibility(self.threeS, false);
	            setVisibility(self.fourS, true);
				
	            -- setVisibility(self.ND, false);
	            -- setVisibility(self.TD, false);
	            -- setVisibility(self.oneSD, false);
	            -- setVisibility(self.twoSD, false);
	            -- setVisibility(self.threeSD, false);
	            -- setVisibility(self.fourSD, true);	
				
				setVisibility(self.F, true);
				setVisibility(self.oneSD1, false);
				setVisibility(self.threeSD1, true);
				
				
            elseif speed >= 37 and speed < 45 then
                setRotation(self.gearShifter, MathUtil.degToRad(20),  MathUtil.degToRad(0), MathUtil.degToRad(0));
	            setVisibility(self.N, false);
	            setVisibility(self.FR, false);
	            setVisibility(self.T, false);
	            setVisibility(self.oneS, false);
	            setVisibility(self.twoS, false);
	            setVisibility(self.threeS, false);
	            setVisibility(self.fourS, true);
				
	            -- setVisibility(self.ND, false);
	            -- setVisibility(self.TD, false);
	            -- setVisibility(self.oneSD, false);
	            -- setVisibility(self.twoSD, false);
	            -- setVisibility(self.threeSD, false);
	            -- setVisibility(self.fourSD, true);
				
				setVisibility(self.F, true);
				setVisibility(self.oneSD1, false);
				setVisibility(self.threeSD1, true);
				
            end;
        end;
        if self.klawishaLH ~= nil then 
            if speed < 0.1 then
                setRotation(self.klawishaLH, MathUtil.degToRad(12),   MathUtil.degToRad(0), MathUtil.degToRad(0));
	            -- setVisibility(self.L, false);
	            -- setVisibility(self.H, false);
	            -- setVisibility(self.LD, false);
	            -- setVisibility(self.HD, false);
            elseif speed >= 0.1 and speed < 15 then
                setRotation(self.klawishaLH, MathUtil.degToRad(20), MathUtil.degToRad(0), MathUtil.degToRad(0));
	            -- setVisibility(self.L, true);
	            -- setVisibility(self.H, false);
	            -- setVisibility(self.LD, true);
	            -- setVisibility(self.HD, false);
            elseif speed >= 15 and speed < 45 then
	            -- setVisibility(self.L, false);
	            -- setVisibility(self.H, true);
	            -- setVisibility(self.LD, false);
	            -- setVisibility(self.HD, true);
                setRotation(self.klawishaLH, MathUtil.degToRad(6), MathUtil.degToRad(0), MathUtil.degToRad(0));
            end;
        end;  
	
	    if self.speedWaitingTimerMonitor < self.speedWaitingMaxTimeMonitor then 
	        -- setVisibility(self.monitorFirst, true); 
		    -- setVisibility(self.monitorSecond, false); 
		    -- setVisibility(self.monitorThird, false); 
	    end;
	    if self.speedWaitingTimerMonitor < (self.speedWaitingMaxTimeMonitor + self.speedWaitingMaxTimeMonitor) and self.speedWaitingTimerMonitor > self.speedWaitingMaxTimeMonitor then 
	        -- setVisibility(self.monitorFirst, false); 
		    -- setVisibility(self.monitorSecond, true); 
		    -- setVisibility(self.monitorThird, false); 
	    end;
	    if self.speedWaitingTimerMonitor < (self.speedWaitingMaxTimeMonitor + self.speedWaitingMaxTimeMonitor + self.speedWaitingMaxTimeMonitor) and self.speedWaitingTimerMonitor > (self.speedWaitingMaxTimeMonitor + self.speedWaitingTimerMonitor) then
    	    -- setVisibility(self.monitorFirst, false); 
		    -- setVisibility(self.monitorSecond, false); 
		    -- setVisibility(self.monitorThird, true); 
	    end;
	    self.speedWaitingTimerMonitor = self.speedWaitingTimerMonitor + dt;
	else 
	    -- self.speedWaitingTimerMonitor = 1; 
		-- setVisibility(self.monitorFirst, false); 
	    -- setVisibility(self.monitorSecond, false); 
	    -- setVisibility(self.monitorThird, false); 
	end;
	end;
	if self:getIsActive() or forceUpdate then	
		if self.gidravlika ~= nil then
			local x,_,_ = getRotation(self.gidravlika);
			self.armMoveAngle = x;
			if self.gidAngle > self.armMoveAngle then
				self.gidRicag.posX = true;
				x,y,z = getRotation(self.gidRicag.node);	
				local newRot = Utils.getMovedLimitedValues({x}, self.gidRicag.maxRot, self.gidRicag.minRot, 1, self.gidRicag.rotTime, dt, true);
				setRotation(self.gidRicag.node, newRot[1],y,z);
			elseif self.gidAngle < self.armMoveAngle then
				self.gidRicag.posX = false;
				x,y,z = getRotation(self.gidRicag.node);	
				local newRot = Utils.getMovedLimitedValues({x}, self.gidRicag.maxRot, self.gidRicag.minRot, 1, self.gidRicag.rotTime, dt, false );
				setRotation(self.gidRicag.node, newRot[1],y,z);
			end;
			if self.gidAngle == self.armMoveAngle then
				if self.gidRicag.posX then
					x,y,z = getRotation(self.gidRicag.node);	
					local newRot = Utils.getMovedLimitedValues({x}, self.gidRicag.minRot, self.gidRicag.Rot, 1, self.gidRicag.rotTime/2, dt, true);
					setRotation(self.gidRicag.node, newRot[1],y,z);
				else
					x,y,z = getRotation(self.gidRicag.node);	
					local newRot = Utils.getMovedLimitedValues({x}, self.gidRicag.maxRot, self.gidRicag.Rot, 1, self.gidRicag.rotTime/2, dt, true);
					setRotation(self.gidRicag.node, newRot[1],y,z);		
				end;
			end;
			self.gidAngle = self.armMoveAngle;
		end;
	end;
end;

function K7:onUpdateTick(dt)
    if self:getIsActive() then
        if self.spec_lights.turnLightState ~= nil then
			if self.blinkerhebel ~= nil then
				local dir = 0;
				local hasRotChanged = false;
				local destRot = self.blinkerhebel.minRot;
				
				if self.spec_lights.turnLightState == 1 then
					destRot = self.blinkerhebel.leftRot;
					dir = 1;
				elseif self.spec_lights.turnLightState == 2 then
					destRot = self.blinkerhebel.rightRot;
					dir = -1;
				end
				
				if self.blinkerhebel.lastDir ~= dir then
					self.blinkerhebel.lastDir = dir;
					self.blinkerhebel.rotatingTime = 0;
				end
				
				if self.blinkerhebel.rotatingTime ~= nil then
					self.blinkerhebel.rotatingTime = self.blinkerhebel.rotatingTime + dt;
					local t = math.min(1.0, self.blinkerhebel.rotatingTime / self.blinkerhebel.rotTime);
					if t == 1 then
						self.blinkerhebel.rotatingTime = nil;
					end
					local rot = {getRotation(self.blinkerhebel.node)};
					
					local rx1,ry1,rz1,rw1 = mathEulerToQuaternion(unpack(rot));
					local rx2,ry2,rz2,rw2 = mathEulerToQuaternion(unpack(destRot));
					
					local qx,qy,qz,qw = MathUtil.nlerpQuaternionShortestPath(rx1,ry1,rz1,rw1, rx2,ry2,rz2,rw2, t);
					setQuaternion(self.blinkerhebel.node, qx,qy,qz,qw);
				end
			end;
		end;
	end;
end;

function K7:playklawishaAnims(animName, animSpeed)    
    local animTime = self:getAnimationTime(animName);
    if not self:getIsAnimationPlaying(animName) then    
        self:playAnimation(animName, animSpeed, animTime, true);
    end;
end;