Hiding thick box then showing another one cause error

Hiding thick box then showing another one cause error

Hi folks,

I have a window that calls tb_show to open a page, 
If i click on the close button, the following JavaScript code executed:
  1. javascript:self.parent.tb_remove();self.parent.showNewShadow();
the showNewShadow function is calling an AJAX and according to the result it shows another shadowbox
  1. function showNewShadow(){
  2. //call ajax
  3. //.......
  4.       if (ajaxResult=='YES'){
  5.       tb_show(...);//show the other page
  6.       }
  7. }

This result on hiding the first shadow but a loading icons remains on the screen and the next shadow is not showing. Also a javascript error is fired ""Jquery is not defined"

In my opinion, the issue is that there is no enough time between hiding the first shadow and showing the next one.
I want to know the ideal solution for this issue, if it happened with some one of you.

Thanks