How does a client decide which is the longest block chain if there is a fork? Is it only the block height or is it the effort that went into the forks? In other words: does this decision account for different difficulties?
Gary's answer is not entirely correct. When comparing two chains, their total "scores" are compared.
Each block counts as (2^256 / block_target); this is the expected/average number of attempts that were necessary to create it.

Obviously, within one series of 2016 blocks, the difficulties are all equal, so for most small reorganizations, the score will tell you the same thing as just counting the number of blocks. However, as an attacker may well try to rewrite blocks that cross the multiple-of-2016-boundary, you need to take this into account. The actual rule always favors the chains which required the most "work".