Potential energy during vertical fall Suppose I have a weightless spring connected perpendicularly to the ground, and it has on top of it some weightless surface. Now, I release some sticky object from height $h$ above the system of light spring-surface. The object eventually hits the surface and the spring is starting to contract till all the kinetic energy of the object is transformed to elastic potential energy. And the system continues to oscillate harmonically. I want to find the maximal contraction of the spring, therefore, I did:
(we assume that no energy is lost during the collision)
$U_{GR}=E_{k,max}=U_{SP, max}$
$mgh=\frac{1}{2}kx_{max}^2$
where $k$ is the stiffness coefficient.
Therefore:
$x_{max}=\sqrt{\frac{2mgh}{k}}$
I've chosen my 0 level for gravitational potential energy to be on the same level as 0 level of potential elastic energy. Suppose I want to choose another 0 level for GPE, e.g. at maximum contraction. Then my equation would be:
$mg(h+x_{max})=\frac{1}{2}kx_{max}^2$
It obviously leads us to a slightly different $x_{max}$ value.
According to the numbers in the answer in my book it seems like the second equation is correct.
My question is - how then correct equations should look like if I want to arbitrary choose my PE 0 level at any point? Or why the first one is wrong?
Also, I'm wondering why the amplitude of the oscillations is not $x_{max}$ (according to the book it is slightly less the correct $x_{max}$ value, even though we assumed that no kinetic energy was lost. Interesting coincidence: the amplitude on the contrary, according to the book, equals to the $x_{max}$ value of my first equation).
 A: The error in the first calculation is that you neglect the fact that the mass continues to fall below your reference level till the maximum extension is reached, so the gravitational energy released is $mg(h+x_\text{max})$ still. The body falls a distance $(h+x_\text{max})$ regardless of where you put the reference level. The relevant quantity is the difference in potentials between the initial point and final point (not the reference level). The arbitrary reference level cancels out and it doesn't matter how you choose it.
A: NOTE: This comment was too long so I'll make it an answer.
I would assume that the amount that the spring contracts is negligible compared to the distance that the mass has fallen. 
But anyway, regarding your amplitude problem: consider that when you have a mass on a level surface connected to the spring, there is an interplay between kinetic and spring potential energies. In that case, the amplitude would be $x_{max}$. However, in this problem, there is an interplay between the kinetic, potential, and spring potential energies. The total energy at any time is $$E=mgh+\frac{1}{2}kx^2+\frac{1}{2}mv^2$$ At the bottom, all energy is spring potential, i.e. $$E= \frac{1}{2}kx^2$$ But at the top, the energy is part-spring potential and part-gravitational potential, like so:$$E=\frac{1}{2}kx^2+mgh$$ Thus it doesn't seem like the amplitude of oscillation would be exactly $x_{max}$. 
