Stable rc

Fix various crashes in the web interface. Fix capture-replace and most of the numbering inconsistencies.
The problem is either here or in the server code. This code was using capture_num while the server code was using sequence_num. I'll take a look at the server-side tonight if you haven't patched this by then.

Steps to reproduce: Click capture, click the camera, click retake, click one of the two preview thumbnails. The lightbox will have a broken image marker instead of the image.