How to make alternate background images animation for a web page

This code can be used to make fade animation alternatively on background images for a web page. 
 
Suppose there are two images and we want to change them in the background with a set interval of time.
 
Then we will create two divs and in the script, we will use fadeToggle for each div in setInterval function. Just like as follows: 
 
CODE:
  1. <div id="bg1">  
  2.     <img src="img/abhi.jpg" />  
  3. </div>  
  4. <div id="bg2">  
  5.     <img src="img/abhi2.jpg" />  
  6. </div>  
  7. <script type="text/javascript">  
  8. $(document).ready(function() {  
  9.     $('#bg2').fadeToggle(8000);  
  10.   
  11.     function loopBackground() {  
  12.         setInterval(function() {  
  13.             $('#bg1').fadeToggle(8000);  
  14.             $('#bg2').fadeToggle(8000);  
  15.         }, 8000);  
  16.     }  
  17.     loopBackground();  
  18. });  
  19. </script>