Check dialog is open before closing in state change

Current code will issue a close and decrement the activeBackdrops value to below 0 when changing state, even when the dialog is already closed.  This causes future dialogs to not have the backdrop inserted afterwards.  A check is needed first before close() to resolve this issue.