How to Get Previous and Next Lesson IDs

This code snippet retrieves the previous and next lesson IDs based on a users last viewed lesson.  A link is echoed if a previous or next lesson exists within the same course.