How to load random background image each day with jquery?

i’ve got some code - using jquery & javascript - that loads a random background image into a div element. the code is below. the trouble is, it loads a random image every time the page is loaded, when what i want is to just pick a random image ONCE each day

anyone any idea of how i’d go about doing this?

<script type="text/javascript">	
   $(document).ready(function() {
      if ($(window).width() > 1200) {		
         var randomImages = ['bgimage0_big', 'bgimage1_big', 'bgimage2_big', 'bgimage3_big'];
         var rndNum = Math.floor(Math.random() * randomImages.length);
         $("div#branding").css({ background: "url(css/images/" + randomImages[rndNum] + ".jpg) no-repeat" });
      } else  {
         var randomImages = ['bgimage0_small', 'bgimage1_small', 'bgimage2_small', 'bgimage3_small'];
         var rndNum = Math.floor(Math.random() * randomImages.length);
         $("div#branding").css({ background: "url(css/images/" + randomImages[rndNum] + ".jpg) no-repeat" });
      }
   });
</script>

One idea would be that when your page first loads, you could set a cookie which would expire at midnight.
Then in the above script, add a line so that whenever it is called, it checks for the presence of the cookie.
If the cookie exists, do nothing. Otherwise, display a random image and set another cookie.
This should help: http://stackoverflow.com/questions/4627821/how-to-expire-a-cookie-using-jquery-at-midnight

that’s perfect, cheers

[ now just to make brain do the implementation thing ]