You could trigger the var bol_thickbox_shown
outside this function and set it to true when the thickbox open and to false if they where closed.
for example:
var bol_thickbox_shown = false;
/* hook this bol_thickbox_shown true/false
to wherever you fire the Thickbox */
document.onkeydown = function(e){
console.log('bol_thickbox_shown: '+bol_thickbox_shown);
if(bol_thickbox_shown && e.keyCode === 116){ // F5 keycode is 116
e.preventDefault();
e.returnValue = false; // for IE
}
}
and even you don't like this solution you could optimize the following line:
var bol_thickbox_shown = ($('#TB_window').is(':visible')) ? true : false;
to
var bol_thickbox_shown = $('#TB_window').is(':visible');