Close the picker on document.mousedown instead of $('body').click, and check with e.target.parents() instead of activePickerId.
Don't close the date picker if e.target is the uncle of a visible date picker.