Why does optical media have different refractive indices? Optical density is a measure of the refracting power of a medium. In other words, the higher the optical density, the more the light will be refracted or slowed down as it moves through the medium. Optical density is related to refractive index in that materials with a high refractive index will also have a high optical density. Light will travel slower through a medium with a high refractive index and high optical density and faster through a medium which has a low refractive index and a low optical density. So to restate the question, why do optical media have different refractive indices?
 A: Refractive index describes the speed of propagation of light in a medium. So to restate your question: 

why is the speed of light slower in some media than in others?

The wave equation tells us that speed of propagation depends on two factors: one is an inertial term, while the other is an elastic term. Let's look at a simple case of a string. The velocity of wave propagation in a string goes as 
$$v = \sqrt\frac{T}{\mu}$$
where $T$ is the tension, and $\mu$ is the mass per unit length.
When light propagates in a dielectric medium, the electrons in that medium are moved by the EM field of the light. These moving electrons in turn emit an electromagnetic wave, but this wave will be lagging in phase with the signal that caused their motion. 
Because of this phase lag, the combined signal that propagates is the sum of the initial signal (now a bit smaller because it gave some of its energy to the electron) plus the phase-shifted signal from the electron. Together, they create a phase shift in the original signal - it is as though it is going slower.
The shift due to one electron is tiny; but the more electrons you have per unit volume, the greater the effect will be. The actual force with which the electrons are bound (the "elastic constant" if you like) also comes into play, so you can't simply say that refractive index scales with density - but for similar materials, it does; the following graph (from http://upload.wikimedia.org/wikipedia/en/3/3b/Density-nd.GIF) shows that similar materials with different densities have a pretty believable relationship between density and refractive index:

The wikipedia page on refractive index contains some more information on the topic...
