
/*
 * randomizeChildren( elementID ) - returns false on error, true on success
 * 
 * randomizes child elements contained within elementID. requires prototype.js 
 * javascript library 
 */
 
function randomizeChildren(id)
{
  if (!id)
  {
    return false;
  }
  
  // grab our parent container
  r = $(id);
  
  if (!r)
  {
    return false
  }

  // create a new array
  ourList = new Array();
  
  /* 
   * iterate through the parent, populate our 
   * array with its children, and remove the original
   * children. 
   */ 
   
  r.childElements().each(
    function(elem)
    {
      ourList.push(elem);
      elem.remove();
    }
  );
  
  /* 
   * now shake our array like it's a
   * chrismas eve present, and you
   * don't want any socks tonight.
   */
   
  for (var index = 0, len = ourList.length; index < len;++index )
  {
    ourList = ourList.sortBy(
                function(list)
                {
                  return parseInt(Math.random()*ourList.length)*parseInt(Math.random()*ourList.length);
                }
              );
  }
  
  /* 
   * re-populate our parent container 
   * with the now (hopefully) randomized 
   * contents, and pray for a return policy. (:
   */
   
  ourList.each(
    function(elem)
    {
      r.appendChild(elem);
    }
  );
  
  return true;
}
