Move the show hide logic from events.js to ui.js
Add checking if infowindow exists before closing it