The code is working fine as far as toggling the image('hidden2') is concerned. However, visibility:hidden css property leaves the space behind.
So you can go with the display property by which the image space will be removed.
document.getElementById('hidden2').style.display= "none";
document.getElementById('hidden2').style.display= "block";