Bug 2114: apply patch from LiveJournal r15922

This is LJ's patch for fixing the previous/next issue.  It looks
like the relevant code has not changed on our end, so I applied it
directly, only tweaking whitespace to match our style guidelines.

THIS IS NOT TESTED.  Please test before committing!
Bug 2114: remove unused variable $cmp2

I noticed that the previous changes cause this $cmp2 variable to be
assigned but not used, so I removed the declaration and assignments.

(Still not tested!)
Merge pull request #411 from kareila/bug2114-20130607a

Bug2114 20130607a