--
-- Fliegl_DK_180_88
-- Class for all Dolly Trailers
--
-- @author  Jack
-- @date  25/04/09
--
-- Copyright (C) Jack

Fliegl = {};

function Fliegl.prerequisitesPresent(specializations)
    return SpecializationUtil.hasSpecialization(Attachable, specializations);
end;

function Fliegl:load(xmlFile)

    self.setFillLevel = SpecializationUtil.callSpecializationsFunction("setFillLevel");

-- KippFunktion
    local tipAnimRootNode = Utils.indexToObject(self.rootNode, getXMLString(xmlFile, "vehicle.tipAnimation#rootNode"));
    self.tipAnimCharSet = 0;
    if tipAnimRootNode ~= nil and tipAnimRootNode ~= 0 then
        self.tipAnimCharSet = getAnimCharacterSet(tipAnimRootNode);
        if self.tipAnimCharSet ~= 0 then
		-- Nach Rechts kippen
            self.clip = getAnimClipIndex(self.tipAnimCharSet, getXMLString(xmlFile, "vehicle.tipAnimation#clip"));
		-- Nach Hinten kippen
            self.clipback = getAnimClipIndex(self.tipAnimCharSet, getXMLString(xmlFile, "vehicle.tipAnimation#clipback"));
		-- Nach Links kippen
            self.clipleft = getAnimClipIndex(self.tipAnimCharSet, getXMLString(xmlFile, "vehicle.tipAnimation#clipleft"));
		-- assignAnimTrackClip(self.tipAnimCharSet, 0, self.clip);
            setAnimTrackLoopState(self.tipAnimCharSet, 0, false);
            self.tipAnimSpeedScale = Utils.getNoNil(getXMLFloat(xmlFile, "vehicle.tipAnimation#speedScale"), 1);
            self.tipAnimDuration = getAnimClipDuration(self.tipAnimCharSet, self.clip);
            if self.tipDischargeEndTime == nil then
                self.tipDischargeEndTime = self.tipAnimDuration*2.0;
            end;
        end;
    end;

-- nach Rechts kippen

    self.tipReferencePointright = Utils.indexToObject(self.rootNode, getXMLString(xmlFile, "vehicle.tipReferencePointright#index"));

-- ParticleSystemright
    self.dischargeParticleSystemsright = {};
    local i = 0;
    while true do
        local key = string.format("vehicle.dischargeParticleSystemsright.dischargeParticleSystemright(%d)", i);
        local t = getXMLString(xmlFile, key .. "#type");
        if t == nil then
            break;
        end;
        local desc = FruitUtil.fruitTypes[t];
        if desc ~= nil then
            local currentPS = {};

            local particleNode = Utils.loadParticleSystem(xmlFile, currentPS, key, self.components, false, "", self.baseDirectory);
            self.dischargeParticleSystemsright[desc.index] = currentPS;
            if self.defaultdischargeParticleSystems == nil then
                self.defaultdischargeParticleSystems = currentPS;
            end;
        end;
        i = i + 1;
    end;

-- nach Rechts kippen (ende)


-- nach Hinten kippen
   self.tipReferencePointback = Utils.indexToObject(self.rootNode, getXMLString(xmlFile, "vehicle.tipReferencePointback#index"));

-- ParticleSystemback
    self.dischargeParticleSystemsback = {};
    local i = 0;
    while true do
        local key = string.format("vehicle.dischargeParticleSystemsback.dischargeParticleSystemback(%d)", i);
        local t = getXMLString(xmlFile, key .. "#type");
        if t == nil then
            break;
        end;
        local desc = FruitUtil.fruitTypes[t];
        if desc ~= nil then
            local currentPS = {};

            local particleNode = Utils.loadParticleSystem(xmlFile, currentPS, key, self.components, false, "", self.baseDirectory);
            self.dischargeParticleSystemsback[desc.index] = currentPS;
            if self.defaultdischargeParticleSystems == nil then
                self.defaultdischargeParticleSystems = currentPS;
            end;
        end;
        i = i + 1;
    end;

-- nach Hinten kippen (ende)

-- nach Links kippen

    self.tipReferencePointleft = Utils.indexToObject(self.rootNode, getXMLString(xmlFile, "vehicle.tipReferencePointleft#index"));

-- ParticleSystemleft
    self.dischargeParticleSystemsleft = {};
    local i = 0;
    while true do
        local key = string.format("vehicle.dischargeParticleSystemsleft.dischargeParticleSystemleft(%d)", i);
        local t = getXMLString(xmlFile, key .. "#type");
        if t == nil then
            break;
        end;
        local desc = FruitUtil.fruitTypes[t];
        if desc ~= nil then
            local currentPS = {};

            local particleNode = Utils.loadParticleSystem(xmlFile, currentPS, key, self.components, false, "", self.baseDirectory);
            self.dischargeParticleSystemsleft[desc.index] = currentPS;
            if self.defaultdischargeParticleSystems == nil then
                self.defaultdischargeParticleSystems = currentPS;
            end;
        end;
        i = i + 1;
    end;

-- nach Links kippen (ende)
--Kippfunktion (ende)		

-- Plane
    self.plane = Utils.indexToObject(self.rootNode, getXMLString(xmlFile, "vehicle.plane#index"));
-- PlaneA
    self.planeA = Utils.indexToObject(self.rootNode, getXMLString(xmlFile, "vehicle.planeA#index"));
	self.planeActive = true;

	
  	self.keys = {};
    local i=0;
    while true do
        local baseName = string.format("vehicle.keys.input(%d)", i);
        local inputName = getXMLString(xmlFile, baseName.. "#name");
        if inputName == nil then
            break;
        end;
        local inputKey = getXMLString(xmlFile, baseName.. "#key");
        if Input[inputKey] == nil then
            print("Error: invalid key '" .. inputKey .. "'  for input event '" .. inputName .. "'");
            break;
        end;
        self.keys[inputName] = Input[inputKey];
        i = i+1;
    end;

--[[Blinker start]]------------------------------------------------------------		
    self.numTurnlights = Utils.getNoNil(getXMLInt(xmlFile, "vehicle.turnlights#count"), 0);
    self.turnlights = {};
    for i=1, self.numTurnlights do
        local turnlightnamei = string.format("vehicle.turnlights.turnlight" .. "%d", i);
        self.turnlights[i] = Utils.indexToObject(self.rootNode, getXMLInt(xmlFile, turnlightnamei .. "#index"));
        setVisibility(self.turnlights[i], false);
    end;	
	self.turnlightsActive = false;
	
    self.numTurnlights2 = Utils.getNoNil(getXMLInt(xmlFile, "vehicle.turnlights2#count"), 0);
    self.turnlights2 = {};
    for i=1, self.numTurnlights2 do
        local turnlightnamei2 = string.format("vehicle.turnlights2.turnlight" .. "%d", i);
        self.turnlights2[i] = Utils.indexToObject(self.rootNode, getXMLInt(xmlFile, turnlightnamei2 .. "#index"));
        setVisibility(self.turnlights2[i], false);
    end;	
	self.turnlightsActive2 = false;	
--[[Blinker ende]]------------------------------------------------------------	

-- Bremslichter
    self.numbrakelights = Utils.getNoNil(getXMLInt(xmlFile, "vehicle.brakelights#count"), 0);
    self.brakelights = {};
    for i=1, self.numbrakelights do
        local brakelightnamei = string.format("vehicle.brakelights.brakelight" .. "%d", i);
        self.brakelights[i] = Utils.indexToObject(self.rootNode, getXMLInt(xmlFile, brakelightnamei .. "#index"));
        setVisibility(self.brakelights[i], false);
    end;

    self.hudBasePoxX = 0.8325;
    self.hudBasePoxY = (1-0.72);
    self.hudBaseWidth = 0.16;
    self.hudBaseHeight = 0.1825;

    self.hudTrailerpath = Utils.getFilename("Fliegl_hud_gross2.png", self.baseDirectory);
    self.hudTrailerPoxX = 0.8325;
    self.hudTrailerPoxY = (1-0.62);
    self.hudTrailerWidth = 0.16;
    self.hudTrailerHeight = 0.165;
    self.hudTrailerOverlay = Overlay:new("hudTrailerDisplay", self.hudTrailerpath, self.hudTrailerPoxX, self.hudTrailerPoxY, self.hudTrailerWidth, self.hudTrailerHeight);

    self.helpPanel = false;
    self.tipright = true;
    self.tipleft = false;
    self.tipback = false;

    self.brakelightsActive = false;
    self.braking = false;
    self.attached = true;
    self.isFliegl = true;
end;

function Fliegl:delete()
	Utils.deleteParticleSystem(self.dischargeParticleSystemsright);
	Utils.deleteParticleSystem(self.dischargeParticleSystemsleft);
	Utils.deleteParticleSystem(self.dischargeParticleSystemsback);
       
end;


function Fliegl:mouseEvent(posX, posY, isDown, isUp, button)
end;

function Fliegl:keyEvent(unicode, sym, modifier, isDown)

--[[Blinker start]]------------------------------------------------------------	
--[[Blinker Rechts]]-----------------------------------------------------------
	if isDown and sym == Input.KEY_KP_3 then
		self.flashLeft = not self.flashLeft;
		self.delayOnLeft = 10;
		self.flashRight = false;
		self.flash = false;
		self.flashlightsRightActive = false;
		self.flashlightsWarnerActive = false;
		self.flashlightsRight2Active = false;
		self.turnlightsActive2 = false;
		self.flashWarner = false;
	end;
--[[Warnblinker]]------------------------------------------------------------	
	if isDown and sym == Input.KEY_KP_5 then
		self.flash = not self.flash;
		self.flashRight = false;
		self.flashLeft = false;
		self.delayOn = 20;
		self.flashlightsRightActive = false;
		self.flashlightsLeftActive = false;
		self.flashWarner = not self.flashWarner;
	end;
--[[Blinker Links]]-----------------------------------------------------------
	if isDown and sym == Input.KEY_KP_1 then
		self.flashRight = not self.flashRight;
		self.delayOnRight = 10;
		self.flashLeft = false;
		self.flash = false;
		self.flashlightsLeftActive = false;
		self.flashlightsWarnerActive = false;
		self.flashlightsLeft2Active = false;
		self.turnlightsActive = false;
		self.flashWarner = false;
	end;	
--[[Blinker ende]]------------------------------------------------------------

	if isDown and sym==self.keys.links then
		self.Go.links = not self.Go.links; 
		self.Done.links = true; 
		end;

	if isDown and sym==self.keys.rechts then
		self.Go.rechts = not self.Go.rechts; 
		self.Done.rechts = true; 
		end;

	if isDown and sym == self.keys.HELP then
		self.helpPanel = not self.helpPanel;
	end;
		if isDown and sym == self.keys.RIGHT then
		self.tipright = not self.tipright;
		self.tipleft = false;
		self.tipback = false;
	end;
		if isDown and sym == self.keys.LEFT then
		self.tipleft = not self.tipleft;
		self.tipright = false;
		self.tipback = false;
	end;
		if isDown and sym == self.keys.BACK then
		self.tipback = not self.tipback;
		self.tipleft = false;
		self.tipright = false;
	end;

--Planen
	 if self.attached then
	if isDown and sym == self.keys.PLANE1 then
		trailer.planeActive = not trailer.planeActive;
	end;
	end;

	if not self.attached then
	if isDown and sym == self.keys.PLANE2 then
		trailer1.planeActive1 = not trailer1.planeActive1;
	end;
	end;
-- Planen (ende)

end;

function Fliegl:setFillLevel(fillLevel, fillType)
    if not self:allowFillType(fillType, false) then
        return;
    end;

    self.currentFillType = fillType;
    self.fillLevel = fillLevel;
    if self.fillLevel > self.capacity then
        self.fillLevel = self.capacity;
    end;
    if self.fillLevel < 0 then
        self.fillLevel = 0;
        -- reset fill type as the trailer is empty
        Utils.setEmittingState(self.dischargeParticleSystemsback[self.currentFillType], false);
        Utils.setEmittingState(self.dischargeParticleSystemsleft[self.currentFillType], false);
        Utils.setEmittingState(self.dischargeParticleSystemsright[self.currentFillType], false);
        self.currentFillType = FruitUtil.FRUITTYPE_UNKNOWN;
    end;
end;


function Fliegl:update(dt)

--[[Blinker start]]------------------------------------------------------------	
	if self.flash then
		if self.delayOn >= 0 then
			self.delayOn = self.delayOn -dt;
		end;
		if not self.flashlightsRightActive then
			if self.delayOn < 0 then
				self.delayOff = 500;
				self.flashlightsRightActive = true;
				self.flashlightsLeftActive = true;
				self.flashlightsWarnerActive = true;
				self.turnlightsActive2 = true;
				self.turnlightsActive = true;
				playSample(self.turn1, 1, 0.7, 0);
			end;
		end;
		if self.delayOff >= 0 then
			self.delayOff = self.delayOff -dt;
		end;
		if self.flashlightsRightActive then
			if self.delayOff < 0 then
				self.delayOn = 500;
				self.flashlightsLeftActive = false;
				self.flashlightsRightActive = false;
				self.flashlightsWarnerActive = false;
				self.turnlightsActive2 = false;
				self.turnlightsActive = false;
				playSample(self.turn2, 1, 0.7, 0);
			end;
		end;
	end;
	
	if self.flashRight then
		if self.delayOnRight >= 0 then
			self.delayOnRight = self.delayOnRight -dt;
		end;
		if not self.flashlightsRightActive then
			if self.delayOnRight < 0 then
				self.delayOffRight = 500;
				self.flashlightsRightActive = true;
				self.turnlightsActive2 = true;
				playSample(self.turn1,1,0.7,0);
			end;
		end;
		if self.delayOffRight >= 0 then
			self.delayOffRight = self.delayOffRight -dt;
		end;
		if self.flashlightsRightActive then
			if self.delayOffRight < 0 then
				self.delayOnRight = 500;
				self.flashlightsRightActive = false;
				self.turnlightsActive2 = false;
				playSample(self.turn2,1,0.7,0);
			end;
		end;
	else
		if not self.flashWarner then
			self.turnlightsActive2 = false;
		end;
	end;
	
		if self.flashLeft then
			if self.delayOnLeft >= -1 then
				self.delayOnLeft = self.delayOnLeft -dt;
			end;
			if not self.flashlightsLeftActive then
				if self.delayOnLeft < 0 then
					self.delayOffLeft = 500;
					self.flashlightsLeftActive = true;
					self.turnlightsActive = true;
					playSample(self.turn1,1,0.7,0);
				end;
			end;
			if self.delayOffLeft >= 0 then
				self.delayOffLeft = self.delayOffLeft -dt;
			end;
			if self.flashlightsLeftActive then
				if self.delayOffLeft < 0 then
					self.delayOnLeft = 500;
					self.flashlightsLeftActive = false;
					self.turnlightsActive = false;
					playSample(self.turn2,1,0.7,0);
				end;
			end;
		else
			if not self.flashWarner then
				self.turnlightsActive = false;
			end;
		end;
		
		if self.turnlightsActive then
			for i=1, self.numTurnlights do
				local turnlight = self.turnlights[i];
				setVisibility(turnlight, self.turnlightsActive);
			end;
		else
			for i=1, self.numTurnlights do
				local turnlight = self.turnlights[i];
				setVisibility(turnlight, self.turnlightsActive, false);
			end;
		end;
    	if self.turnlightsActive2 then
			for i=1, self.numTurnlights2 do
				local turnlight2 = self.turnlights2[i];
				setVisibility(turnlight2, self.turnlightsActive2);
			end;
		else
			for i=1, self.numTurnlights2 do
				local turnlight2 = self.turnlights2[i];
				setVisibility(turnlight2, self.turnlightsActive2, false);
			end;
		end;	
--[[Blinker ende]]------------------------------------------------------------

--[[Bremslicht start]]--
    inputAxisY = InputBinding.getAnalogInputAxis(InputBinding.AXIS_FORWARD);	
    if InputBinding.isAxisZero(inputAxisY) then
        inputAxisY = InputBinding.getDigitalInputAxis(InputBinding.AXIS_FORWARD);
    end;
	if self.attacherVehicle ~= nil then
			if self.brakelightsActive then
				for i=1, self.numbrakelights do
					local brakelight = self.brakelights[i];
					setVisibility(brakelight, self.brakelightsActive);
				end;
			else
				for i=1, self.numbrakelights do
					local brakelight = self.brakelights[i];
					setVisibility(brakelight, self.brakelightsActive, false);
				end;
			end;
			if (self.attacherVehicle.movingDirection*self.attacherVehicle.lastSpeed*(-inputAxisY)) < -0.001 then		
				self.brakelightsActive = true;
				self.braking = true;
			else
				self.brakelightsActive = false;
				self.braking = false;
			end;
		end;
--[[Bremslicht ende]]--


-- Fillsound abschalten

        if self.fillSoundEnabled and self.fillLevel == 0 or self.tipState == Trailer.TIPSTATE_CLOSING then
            stopSample(self.fillSound);
            self.fillSoundEnabled = false;   
        end;

-- KippFunktion
if self.tipState == Trailer.TIPSTATE_CLOSED then

-- nach Rechts kippen (standart)
	if self.tipright then
	self.tipReferencePoint = self.tipReferencePointright;
	assignAnimTrackClip(self.tipAnimCharSet, 0, self.clip);
	end;
-- nach Rechts kippen (ende)

-- Nach Hinten kippen
if self.tipback then
	self.tipReferencePoint = self.tipReferencePointback;
	assignAnimTrackClip(self.tipAnimCharSet, 0, self.clipback);
	end;
-- nach Hinten kippen (ende)

-- Nach Links kippen
if self.tipleft then
	self.tipReferencePoint = self.tipReferencePointleft;
	assignAnimTrackClip(self.tipAnimCharSet, 0, self.clipleft);
end;
-- nach Links kippen (ende)
end;
-- Kippfunktion (ende)	

-- Discharge Systems
-- rechts
if self.tipright then
        Utils.setEmittingState(self.dischargeParticleSystemsright[self.currentFillType], self.lastFillDelta < 0);
end;
-- rechts (ende)

-- hinten
if self.tipback then
        Utils.setEmittingState(self.dischargeParticleSystemsback[self.currentFillType], self.lastFillDelta < 0);
end;
-- hinten (ende)

--links
if self.tipleft then
        Utils.setEmittingState(self.dischargeParticleSystemsleft[self.currentFillType], self.lastFillDelta < 0);
    end;
-- links (ende)

--[[if self.fillLevel == 0 then
        Utils.setEmittingState(self.dischargeParticleSystemsleft[self.currentFillType], false);
        Utils.setEmittingState(self.dischargeParticleSystemsback[self.currentFillType], false);
        Utils.setEmittingState(self.dischargeParticleSystemsright[self.currentFillType], false);
    end;]]

-- renderText(0.01, 0.06, 0.02, string.format("%d", self.lastFillDelta));


-- Discharge Systems (ende)

-- Plane1
		if g_currentMission.currentVehicle ~= nil then
            for i=1, table.getn(g_currentMission.currentVehicle.attachedImplements) do
                if g_currentMission.currentVehicle.attachedImplements[i].object then
		local trailer = g_currentMission.currentVehicle.attachedImplements[i].object;

		if trailer.planeActive then
				local plane = trailer.plane;
				setVisibility(plane);
				
				local planeA = trailer.planeA;
				setVisibility(planeA, false);

		else
				local plane = trailer.plane;
				setVisibility(plane, false);

				local planeA = trailer.planeA;
				setVisibility(planeA);

		end;	
end;
end;
end;

-- Plane1 (ende)	

-- Plane2
            for i=1, table.getn(self.attachedImplements) do
                if self.attachedImplements[i].object then
		local trailer1 = self.attachedImplements[i].object;

		if trailer1.planeActive1 then
				local plane = trailer1.plane;
				setVisibility(plane);
				
				local planeA = trailer1.planeA;
				setVisibility(planeA, false);

		else
				local plane = trailer1.plane;
				setVisibility(plane, false);

				local planeA = trailer1.planeA;
				setVisibility(planeA);

		end;

end;
end;	
-- Plane2 (ende)	

end;


function Fliegl:draw()

		if g_currentMission.currentVehicle ~= nil then
            for i=1, table.getn(g_currentMission.currentVehicle.attachedImplements) do
                if g_currentMission.currentVehicle.attachedImplements[i].object and g_currentMission.currentVehicle.attachedImplements[i].object.isSelected then
		trailer = g_currentMission.currentVehicle.attachedImplements[i].object;

	self.attached = true;

end;
end;
end;
            for i=1, table.getn(self.attachedImplements) do
                if self.attachedImplements[i].object and self.attachedImplements[i].object.isSelected then
		trailer1 = self.attachedImplements[i].object;

	self.attached = false;
end;
end;


	-- SchriftFarbe und Größe
		setTextBold(true);
		setTextColor(1.0, 1.0, 1.0, 1.0);


-- if self.attached and self.isFliegl then
--	self.hudTrailerOverlay:render();
--   renderText(0.01, 0.08, 0.02, string.format("%d", trailer.fillLevel));
--       local percent = trailer.fillLevel/trailer.capacity*100;
--    renderText(self.hudTrailerPoxX+0.02, self.hudTrailerPoxY+0.097, 0.028, string.format("%.0f(%d%%)", trailer.fillLevel, percent));

-- else
--	if trailer1.isFliegl then
 --    renderText(0.01, 0.06, 0.02, string.format("%d", trailer1.fillLevel));
--       local percent = trailer1.fillLevel/trailer1.capacity*100;
 --   renderText(self.hudTrailerPoxX+0.02, self.hudTrailerPoxY+0.065, 0.028, string.format("%.0f(%d%%)", trailer1.fillLevel, percent));
--end;
end;


	-- HelpPanel Anhänger1+2

		if self.attached and self.isFliegl then
		if not self.helpPanel then		
	    	renderText(self.hudTrailerPoxX+0.001, self.hudTrailerPoxY+0.17, 0.02, "Taste "..key_convert(self.keys.HELP)..": Info Einschalten");		
		else
		renderText(self.hudTrailerPoxX+0.001, self.hudTrailerPoxY+0.17, 0.02, "Taste "..key_convert(self.keys.HELP)..": Info Ausschalten");
		end;
			if self.helpPanel then
			renderText(self.hudTrailerPoxX+0.015, self.hudTrailerPoxY+0.39, 0.03, "- Fliegl Info -");
			renderText(self.hudTrailerPoxX+0.042, self.hudTrailerPoxY+0.36, 0.02, "- Planen -");		

			if trailer.planeActive then
				renderText(self.hudTrailerPoxX+0.001, self.hudTrailerPoxY+0.34, 0.02, "Taste "..key_convert(self.keys.PLANE1)..": Plane1 aus");
			else
				renderText(self.hudTrailerPoxX+0.001, self.hudTrailerPoxY+0.34, 0.02, "Taste "..key_convert(self.keys.PLANE1)..": Plane1 an");
			end;

			if self.planeActive1 then
				renderText(self.hudTrailerPoxX+0.001, self.hudTrailerPoxY+0.32, 0.02, "Taste "..key_convert(self.keys.PLANE2)..": Plane2 aus");
			else
				renderText(self.hudTrailerPoxX+0.001, self.hudTrailerPoxY+0.32, 0.02, "Taste "..key_convert(self.keys.PLANE2)..": Plane2 an");
	end;

-- Anhänger1 tip
			renderText(self.hudTrailerPoxX+0.025, self.hudTrailerPoxY+0.29, 0.02, "- KippFunktion -");
			renderText(self.hudTrailerPoxX+0.042, self.hudTrailerPoxY+0.27, 0.02, "Anhänger1+2");
			if self.tipright and self.tipleft == false and self.tipback == false then
				renderText(self.hudTrailerPoxX+0.001, self.hudTrailerPoxY+0.24, 0.02, "Taste "..key_convert(self.keys.RIGHT)..": Rechts ist an");
			else
				renderText(self.hudTrailerPoxX+0.001, self.hudTrailerPoxY+0.24, 0.02, "Taste "..key_convert(self.keys.RIGHT)..": Rechts ist aus");
			end;

			if self.tipright == false and self.tipleft == false and self.tipback then
				renderText(self.hudTrailerPoxX+0.001, self.hudTrailerPoxY+0.22, 0.02, "Taste "..key_convert(self.keys.BACK)..": Hinten ist an");
			else
				renderText(self.hudTrailerPoxX+0.001, self.hudTrailerPoxY+0.22, 0.02, "Taste "..key_convert(self.keys.BACK)..": Hinten ist aus");
			end;

			if self.tipright == false and self.tipleft and self.tipback == false then
				renderText(self.hudTrailerPoxX+0.001, self.hudTrailerPoxY+0.20, 0.02, "Taste "..key_convert(self.keys.LEFT)..": Links ist an");
			else
				renderText(self.hudTrailerPoxX+0.001, self.hudTrailerPoxY+0.20, 0.02, "Taste "..key_convert(self.keys.LEFT)..": Links ist aus");
			end;
			
			end;

	--		end;
end;
       

		-- 2nd trailer

--[[	-- HelpPanel Anhänger1
		
		if self.attached then
		if not self.helpPanel then		
	    	renderText(self.hudTrailerPoxX+0.001, self.hudTrailerPoxY+0.17, 0.02, "Taste "..key_convert(self.keys.HELP)..": Info Einschalten");		
		else
		renderText(self.hudTrailerPoxX+0.001, self.hudTrailerPoxY+0.17, 0.02, "Taste "..key_convert(self.keys.HELP)..": Info Ausschalten");
		end;
		--	if not self.SchneckenSystemActive then
			if self.helpPanel then
			renderText(self.hudTrailerPoxX+0.015, self.hudTrailerPoxY+0.38, 0.03, "- Fliegl Info -");
			renderText(self.hudTrailerPoxX+0.043, self.hudTrailerPoxY+0.35, 0.02, "- Plane -");
			if self.planeActive then
				renderText(self.hudTrailerPoxX+0.001, self.hudTrailerPoxY+0.33, 0.02, "Taste "..key_convert(self.keys.PLANE1)..": Plane1 aus");
			else
				renderText(self.hudTrailerPoxX+0.001, self.hudTrailerPoxY+0.33, 0.02, "Taste "..key_convert(self.keys.PLANE1)..": Plane1 an");
			end;

-- Anhänger1 tip
			renderText(self.hudTrailerPoxX+0.025, self.hudTrailerPoxY+0.30, 0.02, "- KippFunktion -");
			renderText(self.hudTrailerPoxX+0.042, self.hudTrailerPoxY+0.28, 0.02, "Anhänger1");
			if self.tipright and self.tipleft == false and self.tipback == false then
				renderText(self.hudTrailerPoxX+0.001, self.hudTrailerPoxY+0.26, 0.02, "Taste "..key_convert(self.keys.RIGHT)..": Rechts ist an");
			else
				renderText(self.hudTrailerPoxX+0.001, self.hudTrailerPoxY+0.26, 0.02, "Taste "..key_convert(self.keys.RIGHT)..": Rechts ist aus");
			end;

			if self.tipright == false and self.tipleft == false and self.tipback then
				renderText(self.hudTrailerPoxX+0.001, self.hudTrailerPoxY+0.24, 0.02, "Taste "..key_convert(self.keys.BACK)..": Hinten ist an");
			else
				renderText(self.hudTrailerPoxX+0.001, self.hudTrailerPoxY+0.24, 0.02, "Taste "..key_convert(self.keys.BACK)..": Hinten ist aus");
			end;

			if self.tipright == false and self.tipleft and self.tipback == false then
				renderText(self.hudTrailerPoxX+0.001, self.hudTrailerPoxY+0.22, 0.02, "Taste "..key_convert(self.keys.LEFT)..": Links ist an");
			else
				renderText(self.hudTrailerPoxX+0.001, self.hudTrailerPoxY+0.22, 0.02, "Taste "..key_convert(self.keys.LEFT)..": Links ist aus");
			end;

		--	renderText(self.hudTrailerPoxX+0.001, self.hudTrailerPoxY+0.20, 0.02, "Taste "..key_convert(self.keys.SCHNECKENSYSTEM))..": SchneckenSystem an");
			end;
	-- end;


end;
-- end; ]]

	--[[	if self.planeActive and self.attachedTrailer and not self.attachedTrailer1 then
		self.hudTrailerpath = Utils.getFilename("Fliegl_hud_gross_1_zu.png", self.baseDirectory);
	    self.hudTrailerOverlay = Overlay:new("hudTrailerDisplay", self.hudTrailerpath, self.hudTrailerPoxX, self.hudTrailerPoxY, self.hudTrailerWidth, self.hudTrailerHeight);
		else
		self.hudTrailerpath = Utils.getFilename("Fliegl_hud_gross_1_offen.png", self.baseDirectory);
   	 self.hudTrailerOverlay = Overlay:new("hudTrailerDisplay", self.hudTrailerpath, self.hudTrailerPoxX, self.hudTrailerPoxY, self.hudTrailerWidth, self.hudTrailerHeight);
		end;]]


		if self.attached then	
		-- if not self.attachedImplements.SchneckenSystemActive then
		if self.tipright then
			setTextBold(true);
			setTextColor(5.3, 8.3, 0.6, 1.0);			
	    	renderText(self.hudTrailerPoxX+0.07, self.hudTrailerPoxY+0.020, 0.03, "R");
			setTextColor(1.0, 1.0, 1.0, 1.0);
		end;

		if self.tipback  then
			setTextBold(true);
			setTextColor(5.3, 8.3, 0.6, 1.0);			
	    	renderText(self.hudTrailerPoxX+0.07, self.hudTrailerPoxY+0.020, 0.03, "H");
			setTextColor(1.0, 1.0, 1.0, 1.0);
		end;

		if self.tipleft then
			setTextBold(true);
			setTextColor(5.3, 8.3, 0.6, 1.0);			
	    	renderText(self.hudTrailerPoxX+0.07, self.hudTrailerPoxY+0.020, 0.03, "L");
			setTextColor(1.0, 1.0, 1.0, 1.0);
		end;

	-- end;
	end;
		-- Dolly & Dolly Trailer (ende)
	

-- end;

function key_convert(key)
	if key < 256 then
		return string.upper(""..string.char(key).."");
	elseif key > 255 and key < 266 then
		return string.upper("KP"..string.char(key-208));
	else
		return "n/a";
	end;
end;


function Fliegl:mouseEvent(posX, posY, isDown, isUp, button)
end;
