[TCAS](http://en.wikipedia.org/wiki/TCAS) is obviously a fantastic piece of kit, but I was wondering: exactly how does it work?

What I mean is, how does it determine whether to tell a pilot to climb or descend when there's traffic?

Also, can you give an overview of the various types of TCAS, and how planes agree a resolution?