// Copyright (c) 2003-2005 Y-Times Publications, LLC. All Rights Reserved.
// Duplication is not permitted without written permission of Y-Times Publications, LLC.


function ShowBSells(cols)
{
    var FeaturedIndex = new Array;
    var elems = 0;
    do
    {
      idx = Math.floor( Math.random() * Featured.length );
      var IdxFound = false;
      for (i = 0; i < FeaturedIndex.length; i++ )
      {
        if (FeaturedIndex[i] == idx)
        {
          IdxFound = true;
          break;
        }
      }
      if (!IdxFound)
      {
        FeaturedIndex[elems] = idx;
        elems = elems + 1;
      }
    } while (FeaturedIndex.length < FeaturedN);

    document.write("<table class=rbsTbl border=0 width=100% cellpadding=0 cellspacing=0><tr valign=top align=center>");
    for (i = 0 ; i < FeaturedIndex.length; i++)
    {
        if ((i+1) % cols == 0)
            document.write("<td class=rbsLastCell ");
        else
            document.write("<td class=rbsMidCell ");
        document.write( " width=" + (100/cols) + "%>" + String(Featured[FeaturedIndex[i]]).replace(/`/gi, "'") + "</td>");
        if ((i+1) % cols == 0)
        {
            document.write("</tr><tr valign=top align=center>");
        }
    }
    document.write("</tr></table>");
}

function shuffleSpecials() {
    var cols = 3;
    var n = $("#randomSpecials div.rs").length;
    for (var i = 0; i < n; i++) {
        var srcRow = parseInt(i / cols);
        var srcCol = i % cols;
        var srcCell = $("#randomSpecials tr.rs:eq(" + srcRow + ")").find("td.rs:eq(" + srcCol + ")");
        if (srcCell.length > 0) {
            var src = srcCell.find("table.rbsTbl").clone();
            var targetI = parseInt(Math.random() * 12);
            var targetRow = parseInt(targetI / cols);
            var targetCol = targetI % cols;
            var targetCell = $("#randomSpecials tr.rs:eq(" + targetRow + ")").find("td.rs:eq(" + targetCol + ")");
            if (targetCell.length > 0) {
                srcCell.find("table.rbsTbl").replaceWith(targetCell.find("table.rbsTbl").clone());
                targetCell.find("table.rbsTbl").replaceWith(src);
            }
        }
    }
}
