How are BTC-e orders filled? When there is some price overlap, i.e an ask and a higher priced bid, who will get the difference? In other words, will the seller get an "extra", or the buyer a "discount"? I'm interested in BTC-e mainly, but general knowledge about exchanges is useful too.

I looked around here and found similar questions, such as this one, this one, and this one, but still I don't fully understand how it works. 

This answer seems to suggest that the effective price will be that of the order that was in the book, the one placed first. So, assuming volumes match, an ask at $1000 with a bid at $1050 will be filled at $1000 if the ask was placed first, or at $1050 if the bid was placed first. 

Here it's stated that "the exchange will match the buy order with the lowest sell orders", but it's not clear to me if that's the case just in the example given in the question, or always. This other one agrees with the other two, but doesn't say what happens in the opposite case (swapping bids and asks).
Its exactly as you state in the third paragraph.

If you (limit) sell 1 BTC for $1000, you would expect to get $1000. But if someone just placed an order to buy 0.5 BTC for $1050, you will sell to that guy first (so only half of your order) and will receive $525 for that. The other 0.5 BTC you want to sell, sells for $500 (so $1000 / BTC) if someone has that order. So you receive $1025 in total (but fees need to be subtracted), more then you expected. 

The same happens when you buy 1 BTC at $1050. If someone just placed an order to sell 0.5 BTC at $1000, you buy that half coin first for $500. The other 0.5 BTC you ordered is bought for $525. So in total you spent $1025 instead of $1050, but you will receive a whole BTC.