  We present U,B,V,R_C,and I_C photometry of the optical afterglow of the
gamma-ray burst GRB 021004 taken at the Nordic Optical Telescope between
approximately eight hours and 30 days after the burst. This data is combined
with an analysis of the 87 ksec Chandra X-ray observations of GRB 021004 taken
at a mean epoch of 33 hours after the burst to investigate the nature of this
GRB. We find an intrinsic spectral slope at optical wavelengths of beta_UH =
0.39 +/- 0.12 and an X-ray slope of beta_X = 0.94 +/- 0.03. There is no
evidence for colour evolution between 8.5 hours and 5.5 days after the burst.
The optical decay becomes steeper approximately five days after the burst. This
appears to be a gradual break due to the onset of sideways expansion in a
collimated outflow. Our data suggest that the extra-galactic extinction along
the line of sight to the burst is between A_V = 0.3 and A_V = 0.5 and has an
extinction law similar to that of the Small Magellanic Cloud. The optical and
X-ray data are consistent with a relativistic fireball with the shocked
electrons being in the slow cooling regime and having an electron index of p =
1.9 +/- 0.1. The burst occurred in an ambient medium that is homogeneous on
scales larger than approximately 10e18 cm but inhomogeneous on smaller scales.
The mean particle density is similar to what is seen for other bursts (0.1 < n
< 100 cm^{-3}). Our results support the idea that the brightening seen
approximately 0.1 days was due to interaction with a clumpy ambient medium
within 10^{17} and 10^{18} cm of the progenitor. The agreement between the
predicted optical decay and that observed approximately ten minutes after the
burst suggests that the physical mechanism controlling the observed flux
approximately ten minutes is the same as the one operating at t > 0.5 days.
