popup window placement algorithm