How to make a table of content at the top of page?

Ideally, it should be a programmable approach, for example, allow such table of content to be made automatically when the page length is longer than certain configurable threshold.

To insert one where you want it, toc.
Comment by Amitai Sun Jun 5 13:11:40 2011