  (Abridged) We use a combination of high resolution N-body simulations and
semi-analytic techniques to follow the formation, the evolution and the
chemical enrichment of cluster galaxies in a Lambda-CDM Universe. We model the
transport of metals between the stars, the cold gas in galaxies, the hot gas in
dark matter haloes, and the intergalactic gas outside virialized haloes. We
have compared three different feedback schemes. The `retention' model assumes
that material reheated by supernova explosions is able to leave the galaxy, but
not the dark matter halo. The `ejection' model assumes that this material
leaves the halo and is then re-incorporated when structure collapses on larger
scales. The `wind' model uses prescriptions that are motivated by observations
of local starburst galaxies. We require that our models reproduce the cluster
LF from the 2dF survey, the relations between stellar mass, gas mass and
metallicity inferred from new SDSS data, and the observed amount of metals in
the ICM. With suitable adjustment of the free parameters in the model, a
reasonable fit to the observational results at redshift zero can be obtained
for all three feedback schemes. All three predict that the chemical enrichment
of the ICM occurs at high redshift with 60-80 per cent of the metals currently
in the ICM ejected at redshifts larger than 1. Massive galaxies are important
contributors to the chemical pollution. The observed decline in baryon fraction
from rich clusters to galaxy groups is reproduced only in an `extreme' ejection
scheme, where material ejected from dark matter haloes is re-incorporated on a
timescale comparable to the age of the Universe. We explore how the metal
abundance in the intergalactic medium as a function of redshift can constraint
how and when galaxies ejected their metals.
