JavaScript和元素位置

I want to get up to speed on element location and javascript.

ie. if someone clicks on an element, I can show a menu just below that element.

Now I realize I have to account for the fact that if someone clicks on a element to the extreme left/right or bottom of the page, I have to know if the menu is visible on the screen properly.

This seems complicated and would love if there is some tutorial on this very topic?

A quick Google search yielded this result for a Prototype.js context menu. It looks to be exactly what you're looking for.