http://mattgemmell.com/source/#maattachedwindow