Well, there are many little changes you'll need to do, so I'll just give you a hint what to look for, where and what to add.
in details.php search for $sql = "SELECT image_id, cat_id, image_name, image_media_file, image_thumb_file
(you should find at least 3 instances of this line)
at the end of that line add , terms
now it should look like this: $sql = "SELECT image_id, cat_id, image_name, image_media_file, image_thumb_file, terms
This should fix your prev/next thumbnails.
For the random image you'll need search in functions.php for:function get_random_image_cache() {
In that function you'll find 3 $sql queries, do the same (add , terms at the end of the line) to first and third query. Don't touch $sql = "SELECT COUNT(*) as total_images