The reason for the A340's lagging sales are that is has 4 engines. Up until the huge increase in oil prices the A340 was being sold very well. The 500 actualy basicly has the same preformance as the 777. But the 4 engines work out to be less fuel efficient then the 2 for the 777.
Which is why Airbus is developing the A350 which is more advanced then the 777 and A340 and even more fuel efficient. Their engines are 15% more efficient then current engines on the market.