trailertype = {}

function trailertype.prerequisitesPresent(specializations)
      return true;
end;

function trailertype:load(xmlFile)	

 self.Panneaua = Utils.indexToObject(self.components, getXMLString(xmlFile, "vehicle.Panneaua#index"));
 self.Panneaub = Utils.indexToObject(self.components, getXMLString(xmlFile, "vehicle.Panneaub#index"));
 self.Panneauc = Utils.indexToObject(self.components, getXMLString(xmlFile, "vehicle.Panneauc#index"));
 self.Panneaud = Utils.indexToObject(self.components, getXMLString(xmlFile, "vehicle.Panneaud#index"));
 self.Panneaue = Utils.indexToObject(self.components, getXMLString(xmlFile, "vehicle.Panneaue#index"));
 self.Panneauf = Utils.indexToObject(self.components, getXMLString(xmlFile, "vehicle.Panneauf#index"));
 self.Panneaug = Utils.indexToObject(self.components, getXMLString(xmlFile, "vehicle.Panneaug#index"));
 self.Panneauh = Utils.indexToObject(self.components, getXMLString(xmlFile, "vehicle.Panneauh#index"));
 
 if self.Panneaua ~= nil then
 setVisibility(self.Panneaua,false)
 end;
 if self.Panneaub ~= nil then
 setVisibility(self.Panneaub,false)
 end;
 if self.Panneauc ~= nil then
 setVisibility(self.Panneauc,false)
 end;
 if self.Panneaud ~= nil then
 setVisibility(self.Panneaud,false)
 end;
 if self.Panneaue ~= nil then
 setVisibility(self.Panneaue,false)
 end;
 if self.Panneauf ~= nil then
 setVisibility(self.Panneauf,false)
 end;
 if self.Panneaug ~= nil then
 setVisibility(self.Panneaug,false)
 end;
 if self.Panneauh ~= nil then
 setVisibility(self.Panneauh,false)
 end;
 
 self.attachecamion = Utils.indexToObject(self.components, getXMLString(xmlFile, "vehicle.attachecamion#index"));
 self.trailertypea = Utils.indexToObject(self.components, getXMLString(xmlFile, "vehicle.attacheremorque#index"));
 self.trailertypea = Utils.indexToObject(self.components, getXMLString(xmlFile, "vehicle.trailertypea#index"));
 self.trailertypeb = Utils.indexToObject(self.components, getXMLString(xmlFile, "vehicle.trailertypeb#index"));
 self.trailertypec = Utils.indexToObject(self.components, getXMLString(xmlFile, "vehicle.trailertypec#index"));
 self.trailertyped = Utils.indexToObject(self.components, getXMLString(xmlFile, "vehicle.trailertyped#index"));
 self.trailertypee = Utils.indexToObject(self.components, getXMLString(xmlFile, "vehicle.trailertypee#index"));
 self.trailertypef = Utils.indexToObject(self.components, getXMLString(xmlFile, "vehicle.trailertypef#index"));
 self.trailertypeg = Utils.indexToObject(self.components, getXMLString(xmlFile, "vehicle.trailertypeg#index"));
 self.trailertypeh = Utils.indexToObject(self.components, getXMLString(xmlFile, "vehicle.trailertypeh#index"));
 self.remorqueattache = false;

end;

function trailertype:delete()
end;

function trailertype:readStream(streamId, connection)
end;
  
function trailertype:writeStream(streamId, connection)
end;

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

function trailertype:keyEvent(unicode, sym, modifier, isDown)    
end;

function trailertype.gettrailertypeaInRange(self)

	local nearestDistance = 1.0;
	local panneaua = nil;
	for i=1, table.getn(g_currentMission.vehicles) do
	local fredzaza = g_currentMission.vehicles[i];
	if fredzaza.trailertypea ~= nil then
	
		if fredzaza.remorqueattache~= nil then
			if fredzaza.remorqueattache then
				if self.attachecamion ~= nil then
					local px, py, pz = getWorldTranslation(self.attachecamion);
					local vx, vy, vz = getWorldTranslation(fredzaza.trailertypea);
					local distance = Utils.vector3Length(px-vx, py-vy, pz-vz);								 
						if distance < nearestDistance then
                           nearestDistance = distance;
                           panneaua = fredzaza.trailertypea;
 						 end;
					end;
			end;
       end;
	end;
	end;
    return panneaua;
	  
end;

function trailertype.gettrailertypebInRange(self)

	local nearestDistance = 1.0;
	local panneaub = nil;
	for i=1, table.getn(g_currentMission.vehicles) do
	local fredzaza = g_currentMission.vehicles[i];
	if fredzaza.trailertypeb ~= nil then
	
		if fredzaza.remorqueattache~= nil then
			if fredzaza.remorqueattache then
				if self.attachecamion ~= nil then
					local px, py, pz = getWorldTranslation(self.attachecamion);
					local vx, vy, vz = getWorldTranslation(fredzaza.trailertypeb);
					local distance = Utils.vector3Length(px-vx, py-vy, pz-vz);								 
						if distance < nearestDistance then
                           nearestDistance = distance;
                           panneaub = fredzaza.trailertypeb;
 						 end;
					end;
			end;
       end;
	end;
	end;
    return panneaub;
	  
end;

function trailertype.gettrailertypecInRange(self)

	local nearestDistance = 1.0;
	local panneauc = nil;
	for i=1, table.getn(g_currentMission.vehicles) do
	local fredzaza = g_currentMission.vehicles[i];
	if fredzaza.trailertypec ~= nil then
	
		if fredzaza.remorqueattache~= nil then
			if fredzaza.remorqueattache then
				if self.attachecamion ~= nil then
					local px, py, pz = getWorldTranslation(self.attachecamion);
					local vx, vy, vz = getWorldTranslation(fredzaza.trailertypec);
					local distance = Utils.vector3Length(px-vx, py-vy, pz-vz);								 
						if distance < nearestDistance then
                           nearestDistance = distance;
                           panneauc = fredzaza.trailertypec;
 						 end;
					end;
			end;
       end;
	end;
	end;
    return panneauc;
	  
end;

function trailertype.gettrailertypedInRange(self)

	local nearestDistance = 1.0;
	local panneaud = nil;
	for i=1, table.getn(g_currentMission.vehicles) do
	local fredzaza = g_currentMission.vehicles[i];
	if fredzaza.trailertyped ~= nil then
	
		if fredzaza.remorqueattache~= nil then
			if fredzaza.remorqueattache then
				if self.attachecamion ~= nil then
					local px, py, pz = getWorldTranslation(self.attachecamion);
					local vx, vy, vz = getWorldTranslation(fredzaza.trailertyped);
					local distance = Utils.vector3Length(px-vx, py-vy, pz-vz);								 
						if distance < nearestDistance then
                           nearestDistance = distance;
                           panneaud = fredzaza.trailertyped;
 						 end;
					end;
			end;
       end;
	end;
	end;
    return panneaud;
	  
end;

function trailertype.gettrailertypeeInRange(self)

	local nearestDistance = 1.0;
	local panneaue = nil;
	for i=1, table.getn(g_currentMission.vehicles) do
	local fredzaza = g_currentMission.vehicles[i];
	if fredzaza.trailertypee ~= nil then
	
		if fredzaza.remorqueattache~= nil then
			if fredzaza.remorqueattache then
				if self.attachecamion ~= nil then
					local px, py, pz = getWorldTranslation(self.attachecamion);
					local vx, vy, vz = getWorldTranslation(fredzaza.trailertypee);
					local distance = Utils.vector3Length(px-vx, py-vy, pz-vz);								 
						if distance < nearestDistance then
                           nearestDistance = distance;
                           panneaue = fredzaza.trailertypee;
 						 end;
					end;
			end;
       end;
	end;
	end;
    return panneaue;
	  
end;

function trailertype.gettrailertypefInRange(self)

	local nearestDistance = 1.0;
	local panneauf = nil;
	for i=1, table.getn(g_currentMission.vehicles) do
	local fredzaza = g_currentMission.vehicles[i];
	if fredzaza.trailertypef ~= nil then
	
		if fredzaza.remorqueattache~= nil then
			if fredzaza.remorqueattache then
				if self.attachecamion ~= nil then
					local px, py, pz = getWorldTranslation(self.attachecamion);
					local vx, vy, vz = getWorldTranslation(fredzaza.trailertypef);
					local distance = Utils.vector3Length(px-vx, py-vy, pz-vz);								 
						if distance < nearestDistance then
                           nearestDistance = distance;
                           panneauf = fredzaza.trailertypef;
 						 end;
					end;
			end;
       end;
	end;
	end;
    return panneauf;
	  
end;

function trailertype.gettrailertypegInRange(self)

	local nearestDistance = 1.0;
	local panneaug = nil;
	for i=1, table.getn(g_currentMission.vehicles) do
	local fredzaza = g_currentMission.vehicles[i];
	if fredzaza.trailertypeg ~= nil then
	
		if fredzaza.remorqueattache~= nil then
			if fredzaza.remorqueattache then
				if self.attachecamion ~= nil then
					local px, py, pz = getWorldTranslation(self.attachecamion);
					local vx, vy, vz = getWorldTranslation(fredzaza.trailertypeg);
					local distance = Utils.vector3Length(px-vx, py-vy, pz-vz);								 
						if distance < nearestDistance then
                           nearestDistance = distance;
                           panneaug = fredzaza.trailertypeg;
 						 end;
					end;
			end;
       end;
	end;
	end;
    return panneaug;
	  
end;

function trailertype.gettrailertypehInRange(self)

	local nearestDistance = 1.0;
	local panneauh = nil;
	for i=1, table.getn(g_currentMission.vehicles) do
	local fredzaza = g_currentMission.vehicles[i];
	if fredzaza.trailertypeh ~= nil then
	
		if fredzaza.remorqueattache~= nil then
			if fredzaza.remorqueattache then
				if self.attachecamion ~= nil then
					local px, py, pz = getWorldTranslation(self.attachecamion);
					local vx, vy, vz = getWorldTranslation(fredzaza.trailertypeh);
					local distance = Utils.vector3Length(px-vx, py-vy, pz-vz);								 
						if distance < nearestDistance then
                           nearestDistance = distance;
                           panneauh = fredzaza.trailertypeh;
 						 end;
					end;
			end;
       end;
	end;
	end;
    return panneauh;
	  
end;

function trailertype:update(dt)

				if self.Panneaua ~= nil then
                    local panneaua = trailertype.gettrailertypeaInRange(self);
					if panneaua ~= nil then
						setVisibility(self.Panneaua,true)
						else
						setVisibility(self.Panneaua,false)       
					end;
				end;
				
				if self.Panneaub ~= nil then
                    local panneaub = trailertype.gettrailertypebInRange(self);
					if panneaub ~= nil then
						setVisibility(self.Panneaub,true)
						else
						setVisibility(self.Panneaub,false)       
					end;
				end;
				
				if self.Panneauc ~= nil then
                    local Panneauc = trailertype.gettrailertypecInRange(self);
					if Panneauc ~= nil then
						setVisibility(self.Panneauc,true)
						else
						setVisibility(self.Panneauc,false)       
					end;
				end;
				
				if self.Panneaud ~= nil then
                    local Panneaud = trailertype.gettrailertypedInRange(self);
					if Panneaud ~= nil then
						setVisibility(self.Panneaud,true)
						else
						setVisibility(self.Panneaud,false)       
					end;
				end;
				
				if self.Panneaue ~= nil then
                    local Panneaue = trailertype.gettrailertypeeInRange(self);
					if Panneaue ~= nil then
						setVisibility(self.Panneaue,true)
						else
						setVisibility(self.Panneaue,false)       
					end;
				end;
				
				if self.Panneauf ~= nil then
                    local Panneauf = trailertype.gettrailertypefInRange(self);
					if Panneauf ~= nil then
						setVisibility(self.Panneauf,true)
						else
						setVisibility(self.Panneauf,false)       
					end;
				end;
				
				if self.Panneaug ~= nil then
                    local Panneaug = trailertype.gettrailertypegInRange(self);
					if Panneaug ~= nil then
						setVisibility(self.Panneaug,true)
						else
						setVisibility(self.Panneaug,false)       
					end;
				end;
				
				if self.Panneauh ~= nil then
                    local Panneauh = trailertype.gettrailertypehInRange(self);
					if Panneauh ~= nil then
						setVisibility(self.Panneauh,true)
						else
						setVisibility(self.Panneauh,false)       
					end;
				end;
               
end;

function trailertype:onAttach() 
self.remorqueattache = true;     
end; 

function trailertype:onDetach()
self.remorqueattache = false;
end; 

function trailertype:draw()  	
end;