Avoid document overflow

Added some logic to avoid the menu being outside of the window's bounding box.

Screenshots demonstrating feature:
![screen shot 2014-07-15 at 8 52 50 pm](https://cloud.githubusercontent.com/assets/3921894/3594122/6f010e1e-0c94-11e4-97f3-b56b037ae82e.png)
![screen shot 2014-07-15 at 8 52 58 pm](https://cloud.githubusercontent.com/assets/3921894/3594123/6f03198e-0c94-11e4-96c5-172c99817365.png)
![screen shot 2014-07-15 at 8 53 06 pm](https://cloud.githubusercontent.com/assets/3921894/3594124/6f06536a-0c94-11e4-85bf-ed16609020c8.png)