All pastes #234008 Raw Edit

Miscellany

public text v1 · immutable
·published 2006-11-02 07:37 UTC
rendered paste body
/**
 * After the document has finished loading
 */
$(document).ready(function() {
  loadBlock('/mothersclick.com/front/qa', '#front-qa');
  loadBlock('/mothersclick.com/front/group', '#front-group');
});

function loadBlock(path, id) {
  $.getJSON(path, function(json) {
    qa = json;
    var newIndex;
    var lastIndex;
    interval = Math.floor(Math.random() * 2000 + 2000);
  
    setInterval(function() {
      do {
        newIndex = Math.floor(Math.random() * qa.length);
      }
      while (newIndex == lastIndex);

      $(id +' li:last').hide('slow', function(){ 
        $(this).remove(); 
      });

      $(qa[newIndex]).hide().prependTo(id).show('slow');
    
      lastIndex = newIndex;
    }, interval);
  });
}