Implement and make use of 'query_replace' template tag.

Removes need to hard-code full length replacement query hrefs throughout.
Also allows us to use a query key to choose whether to show thumbnails,
drop the javascript.