Grid, images and a kind of counter in JavaScript