Simplify flyout javascript