I'm using the following code to toggle though some divs

function Toggle(IDS,n) { 

  for (i=0; i<n; i++) { document.getElementById('DB'+i).style.display='none'; } 
  document.getElementById('DB'+IDS).style.display = ''; 

document.getElementById('DB'+IDS).style.display = 'none'; 

}, 10000);

Would somebody be able to help me modify the code to do the following:

1. To close the div if a mouse button is clicked OUTSIDE of the div currently opened.

2. If the mouse is NOT hovering over the currently opened div, then wait 9 seconds, then close the div. (Unless in that 9 seconds, the mouse hovers over the div again)

Many thanks,