All pastes #234018 Raw Edit

Unnamed

public text v1 · immutable
·published 2006-11-02 07:47 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) {
    var newIndex;
    var lastIndex;
    interval = Math.floor(Math.random() * 2000 + 2000);
  
    setInterval(function() {
      // avoid calling the same index twice in a row
      do {
        newIndex = Math.floor(Math.random() * json.length);
      }
      while (newIndex == lastIndex);

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

      $(json[newIndex]).hide().prependTo(id).show('slow');
      
      interval = Math.floor(Math.random() * 2000 + 2000);
    
      lastIndex = newIndex;
    }, interval);
  });
}