What kind of damage is expected to happen to the earth in case of being hit by a direct gamma ray burst? I understand how the ozone layer would be quickly depleted and the UV radiation from the sun would reach the ground...etc
I understand all this, but what confuses me is where all this huge amount of energy would go if our atmosphere stopped it ?
As far as I know, gamma rays will be stopped by the earth's atmosphere and the rays will not touch the ground, also, a typical GRB has about 10^43 to 10^45 joules of energy for the gamma photons, so where would this huge amount of energy go if our atmosphere absorbed it other than ozone depletion ? Would it heat the atmosphere to thousands of degrees ? Or am I just wrong about something here ?
 A: Using the values from the Wikipedia article, let's say we have two $10^{44}\ \mathrm{J}$ GRBs, each beaming their energy uniformly in two beams with half angles of $1^\circ$.
If the energy were not beamed, it would be distributed evenly over the area of the sphere centered on the GRB with radius equal to the GRB-Earth separation $d$. However the actual area $A$ of this sphere that is illuminated is instead
$$ A = 4\pi d^2 \frac{2\cdot\pi (1^\circ)^2}{4\pi (180^\circ/\pi)^2}, $$
where the numerator is the angular area of the beams and the denominator gives the number of square degrees in the whole sphere.
Whatever the formula for $A$, the fraction of the burst energy received by Earth is simply
$$ f = \frac{\pi R_\oplus^2}{A}, $$
where $R_\oplus = 6{,}371\ \mathrm{km}$ is the radius of Earth.
Suppose one GRB is rather close in our galaxy, at a distance of $10{,}000$ light years, $d_1 = 9.5\times10^{19}\ \mathrm{m}$, and another is at $7.5$ billion light years, $d_2 = 7.1\times10^{25}\ \mathrm{m}$. Then the fractions of the total energy received by the whole planet are $f_1 = 7.4\times10^{-24}$ and $f_2 = 1.3\times10^{-35}$ -- very small portions indeed.
The total energies received are $E_1 = 7.4\times10^{20}\ \mathrm{J}$ and $E_2 = 1.3\times10^9\ \mathrm{J}$, which sounds like a lot especially in the first case. However, the mass of the atmosphere is $5\times10^{21}\ \mathrm{g}$, and air has a specific heat capacity of something like $1\ \mathrm{J/(g\cdot K)}$. If all the energy is dissipated in the atmosphere, the nearby GRB will raise the temperature of the atmosphere by about $0.1^\circ\mathrm{C}$, while the distant one will raise it by about $(2\times10^{-13})^\circ\mathrm{C}$.

That takes care of temperature. Direct biological effects of radiation are much trickier, so I'll only briefly touch on them. In another answer of mine I go into detail about calculating how much radiation passes through material. The important points are that the atmosphere is equivalent to $1\ \mathrm{m}$ of lead, which has an attenuation coefficient of about $0.2\ \mathrm{cm^{-1}}$ for gamma rays. Thus the atmosphere blocks all but about $10^{-10}$ of the incoming gamma radiation.
Suppose the nearer GRB went off. The surface of Earth would receive $8\times10^{-4}\ \mathrm{J/m^2}$ in gamma rays. Say a person lying down is $2\ \mathrm{m}$ tall, $40\ \mathrm{cm}$ wide, and $75\ \mathrm{kg}$ in mass. If he (unrealistically) absorbs all gamma rays passing through his body, he will receive $9\times10^{-6}\ \mathrm{J/kg}$. This is about $1\ \mathrm{mrem}$, which is the typical daily background exposure.
