Randomize ul li content on page load

Randomize ul li content on page load

I've tried to do this several times, and so far I can only get my content slide to randomize the order in which the slides are displayed to the user. What i mean by that is that it keeps the same order, but just displays them randomly. I actually need the ORDER of the slides randomized on page load. For example, I have a ul like so:

  1. <ul class="rotator">
  2. <li>Slide 1</li>
  3. <li>Slide 2</li>
  4. <li>Slide 3</li>
  5. <li>Slide 4</li>
  6. <li>Slide 5</li>
  7. </ul>
And then a pager that is created on the fly below it that allows the user to go back and forth between slides

  1. <div class="rotatorNavigation>
  2. <a href="#" name="1">1</a>
  3. <a href="#" name="2">2</a>
  4. <a href="#" name="3">3</a>
  5. <a href="#" name="4">4</a>
  6. <a href="#" name="5">5</a>
  7. </div>
I want the pager order to remain the same, as in 1-5, but the slides I want those to be random. So when you load the page, your order could be like 2,5,3,4,1 OR if you refresh again, your order could be 3,5,1,2,4 etc...

Right now, the jquery we have is like so:

  1. /**
  2.  * Prepare a rotator
  3.  * @return null
  4.  */
  5. (function($)
  6. {
  7. $.fn.prepRotator = function()
  8. {
  9. return this.each(function()
  10. {
  11. // Set the navigation
  12. var count = $(this).children().length;
  13. for (i = 1; i <= count; i++)
  14. {
  15. $(this).siblings('#rotatorNavigation').append("<a href='#' name='" + i + "'>" + i + "</a>");
  16. $(this).children(':eq(' + (i-1) + ')').attr('name', i);
  17. }
  18. $(this).children().preload();
  19. $(this).siblings('#rotatorNavigation').find('a:first').addClass('active');
  20. // Set the rotation
  21. function rotate()
  22. {
  23. if ($('.rotator li.active').next('li').length > 0)
  24. $('.rotator li.active').next('li').showRotatorItem();
  25. else
  26. $('.rotator li:first').showRotatorItem();
  27. globals.RotatorTimeout = setTimeout(function(){ rotate(); }, 5000);
  28. }
  29. globals.RotatorTimeout = setTimeout(function(){ rotate(); }, 5000);
  30. // Set the buttons
  31. $('#rotatorNavigation a').unbind('click').click(function()
  32. {
  33. $(".rotator").find("li[name='" + $(this).attr('name') + "']").showRotatorItem();
  34. clearTimeout(globals.RotatorTimeout);
  35. globals.RotatorTimeout = setTimeout(function(){ rotate(); }, 5000);
  36. return false;
  37. });
  38. });
  39. };
  40. })(jQuery);


  41. /**
  42.  * Show the given rotator item
  43.  * @return null
  44.  */
  45. (function($)
  46. {
  47. $.fn.showRotatorItem = function()
  48. {
  49. return this.each(function()
  50. {
  51. $(this).siblings('.active').removeClass('active').fadeOut();
  52. $(this).fadeIn().addClass('active');
  53. $('#rotatorNavigation a.active').removeClass('active');
  54. $('#rotatorNavigation').find("a[name='" + $(this).attr('name') + "']").addClass('active');
  55. var num = Number($(this).attr('name'));
  56. $('#rotatorNavigation span.triangle').animate(
  57. {
  58. left: $('#rotatorNavigation a.active').position().left + (num > 9 ? 14 : 11)
  59. }, 'fast');
  60. });
  61. };
  62. })(jQuery);
How would I randomize this?