Looking at it again, this is probably for the best; when writing my comment above I had forgotten about the sign out box. The other alternative is to take the if logged in/not in statement out of the php layer and push it entirely into the javascript layer such that this becomes one large block of javascript. Then the button declaration could be within the same javascript, at the end in either case.