I have this webpage with many ads. Currently I have them appearing in a random order without repeating each time the page is refreshed. The code for that is here..

<div id="ads">
    <script type="text/javascript">
        var i, images = [];

        // insert ads here
       
        images.push("<img src='Images/xxxxx.jpg' alt='' />");
        images.push("<img src='Images/xxxxx.jpg' alt='' />");
        images.push("<a href='http://www.xxxxx.com' target='_blank'><img src='Images/xxxx.jpg' alt='' title='Visit www.xxxxx.com' /></a>"); 
        images.push("<a href='http://www.xxxxxx.com' target='_blank'><img src='Images/xxxxxxx.jpg' alt='' title='Visit www.xxxxxxx.com' /></a>");
        images.push("<img src='Images/xxxxxx.jpg' alt='' />");
        images.push("<img src='Images/xxxxxx.jpg' alt='' />");
        images.push("<a href='http://www.xxxxxxx.com/' target='_blank'><img src='Images/xxxxxx.jpg' alt='' title='Visit www.xxxxxx.com' /></a>");           
        images.push("<a href='http://www.xxxxxx.com' target='_blank'><img src='Images/xxxxxx.jpg' alt='' title='Visit www.xxxxxx.com' /></a>");
        images.push("<a href='http://www.xxxxxx.com' target='_blank'><img src='Images/xxxxxx.jpg' alt='' title='Visit www.xxxxxx.com' /></a>");
        images.push("<img src='Images/xxxxxx.jpg' alt='' />");
        images.push("<a href='http://www.xxxxxx.ca' target='_blank'><img src='Images/xxxxxx.jpg' alt='' title='Visit www.xxxxxx.ca' /></a>");
        
images.sort(function() 
        { 
            return 0.5 - Math.random();
        });        
        for(var i = 0; i < images.length; i++)
        {
            document.write(images[i]);
        }
    </script>
    </div>

what I need to do now is group these ads by size, and randomize them within their group as well as randomize the groups each time the page is refreshed.
I hope I have explained this clearly and that someone can help me out. Thanks.

Nevermind, I was able to figure it out. Here's my solution in case you are interested.

<div id="ads">
    <script type="text/javascript">
        var i;
        var images_small = [];
        var images_regular = [];
        var images_large = [];
        var images_xlarge = [];
        var images =  [images_small, images_regular, images_large, images_xlarge];
        // insert ads here
        
        //SMALL 
        images_small.push("<img src='Images/xxx.jpg' alt='' />",
        "<img src='Images/xxx.jpg' alt='' />",
       "<a href='http://www.xxx.com' target='_blank'><img src='Images/xxx.jpg' alt='' title='Visit www.xxx.com' /></a>",
        "<a href='http://www.xxx.com' target='_blank'><img src='Images/xxx.jpg' alt='' title='Visit www.xxx.com' /></a>",
        "<img src='Images/xxx.jpg' alt='' />",
        "<img src='Images/xxx.jpg' alt='' />");

          images_small.sort(function() 
        { 
            return 0.5 - Math.random();
        });        
      

        //REGULAR
        images_regular.push("<a href='http://www.xxx.com/' target='_blank'><img src='Images/xxx.jpg' alt='' title='Visit www.xxx.com' /></a>",          
        "<a href='http://www.xxx.com' target='_blank'><img src='Images/xxx.jpg' alt='' title='Visit www.xxx.com' /></a>",
        "<a href='http://www.xxx.com' target='_blank'><img src='Images/xxx.jpg' alt='' title='Visit www.xxx.com' /></a>",
       "<img src='Images/xxx.jpg' alt='' />",
        "<a href='http://www.xxx.ca' target='_blank'><img src='Images/xxx.jpg' alt='' title='Visit www.xxx.ca' /></a>");

          images_regular.sort(function() 
        { 
            return 0.5 - Math.random();
        });        
       

        //LARGE
        images_large.push("<img src='Images/xxx.jpg' alt='' />",
        "<a href='http://www.xxx.com' target='_blank'><img src='Images/xxx.jpg' alt='' title='Visit www.xxx.com' /></a>");

          images_large.sort(function() 
        { 
            return 0.5 - Math.random();
        });        
        

        //X-LARGE 
        images_xlarge.push("<img src='Images/xxx.jpg' alt='' />",
        "<a href='http://www.xxx.com' target='_blank'><img src='Images/xxx.jpg' alt='' title='Visit www.xxx.com' /></a>",
        "<a href='http://www.xxx.ca' target='_blank'><img src='Images/xxx.jpg' alt='' title='Visit www.xxx.ca' /></a>",
        "<a href='http://www.xxx.ca' target='_blank'><img src='Images/xxx.jpg' alt='' title='Visit www.xxx.ca' /></a>",
        "<a href='http://www.xxx.com' target='_blank'><img src='Images/xxx.jpg' alt='' title='Visit www.xxx.com' /></a>");        
      
            images_xlarge.sort(function() 
        { 
            return 0.5 - Math.random();
        });        
       
        
        
            images.sort(function() 
        { 
            return 0.5 - Math.random();
        });        
        for(var i = 0; i < images.length; i++)
        {
            document.write(images[i]);
        }
  
 
    </script>
    </div>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.