Hat makers used to use mercury (or 'quicksilver') as a means of shaping their hats. They would take a mould and lay the material over it, and then pour the very heavy liquid metal in to form the shape. Mercury is poisonous and sends you insane if you come into contact with it a lot. Hence mad as a hatter.