title: rails flash[:notice] after ajax submit, with jquery Timeout misses timeout if page not ready?
body: <p>I have an problem regarding a flash :notice which is displayed after an ajax submit. </p>
  
  <p>I have a pop up box to leave a message which is submitted with ajax, after the user clicks submit the pop up box disappears and then the #flash slides out to show the message and then slides back away after.</p>
  
  <p>The problem is that I have a timeout function which allows time for the form to fade away before the flash appears (and also a timeout before the #flash disappears), that all works fine apart from when the page isn't fully loaded the message seems to miss the timeout completely, like if i quickly submit a message when the page appears to be ready the flash will quickly slide out and then be gone before anyone could read it.</p>
  
  <p>This is my code and also I'm new to js:</p>
  
  <pre><code>var el = $('#new_message'); //grab the form
  
  setTimeout(showFlashMessages, 800);
  setTimeout(hideFlashMessages, 6000);
  
  // this makes the message form disappear
  $('#message_pad').animate({'top':'-300px'},500,function(){
    $('#overlay').fadeOut('fast');
  });
  
  //this refreshes the flash partial
  $('#flash').html('&lt;%= escape_javascript render( :partial =&gt; 'layouts/flash' ) %&gt;');
  
  //this slides out the flash
  function showFlashMessages() {
    $('#flash').animate({"top": "+=50px"}, 200)
  }
  
  //this hides the flash
  function hideFlashMessages() {
    $('#flash').animate({"top": "-=50px"}, 200)
  }
  
  // Clear form
  el.find('textarea').val('');  
  </code></pre>
  
  <p>If there is a better way to do all this some guidance would be appreciated.</p>
  
  <p>Thanks in advance :)</p>