  We construct a quantum statistical mechanical system which generalizes the
Bost-Connes system to imaginary quadratic fields K of arbitrary class number
and fully incorporates the explict class field theory for such fields. This
system admits the Dedekind zeta function as partition function and the Idele
class group as group of symmetries. The extremal KMS states at zero temperature
intertwine this symmetry with the Galois action on the values of the states on
the arithmetic subalgebra. We also give an interpretation of the original BC
system and of the GL(2) system in terms of Shimura varieties, which motivates
the construction for imaginary quadratic fields. The geometric notion
underlying the construction is that of commensurability of K-lattices.
