try{SC.addVersion('0108', '1.0.000', 'Randomly Displayed Best Sellers');}catch(err){}; 
var scRandConts = function() {
        /*
                scRandConts - Public - Initializes the a random contents set
                PARAMETERS:     none
                RETURN: none
        */
        var itemsArr = [];
        
        this.addObj = function( id, name, name2, img, price, saleprice, alt ) {
                /*
                        addObj - Public - Adds an item into the contents set
                        PARAMETERS:     id - the item id as a string
                                                name - the item name as a string
                                                img - the item image path as a string
                                                price - the item price as a string
                                                saleprice - the item sale price as a string
                        RETURN: none
                */
                itemObj( id, name, name2, img, price, saleprice, alt );
        };
        
        this.display = function( elmId, num, cols, format ) {
                /*
                        display - Public - Displays a random set of contents in an existing HTML element
                        PARAMETERS:     elmId - the id for the HTML element in which the random contents will display as a string
                                                num - the number of random items to display as an integer
                                                cols - the number of columns to display in the contents table as an integer
                                                format - the format of the contents table (should be "vertical" or "ell") as a string
                        RETURN: none
                */
                displayRandConts( elmId, num, itemsArr, cols, format );
        };
        
        function itemObj( id, name, name2, img, price, saleprice, alt ) {
                /*
                        itemObj - Private - Adds an item into the contents set (itemsArr)
                        PARAMETERS:     id - the item id as a string
                                                name - the item name as a string
                                                img - the item image path as a string
                                                price - the item price as a string
                                                saleprice - the item sale price as a string
                        RETURN: none
                */
                var tmp = {};
                tmp.id = id.toLowerCase();
                tmp.name = name;
                tmp.name2 = name2;
                tmp.img = img;
                tmp.price = price;
                tmp.saleprice = saleprice;
				tmp.alt = alt;
                itemsArr.push(tmp);
        }
        
        function drcImg( iObj ){
                /*
                        drcImg - Private - Builds the HTML for an item's image
                        PARAMETERS:     iObj - an item object
                        RETURN: a string containing the HTML code to display the image
                */
                var tContent = "";
                if (iObj.img != "-@NULL@-") {
                        tContent += "<a href=\"" + iObj.id + ".html\"><img alt=\"" + iObj.alt + "\" src=\"" + iObj.img + "\" /></a>";
                }
                return tContent;
        }
        
        function drcInfo( iObj ){
                /*
                        drcInfo - Private - Builds the HTML for an item's name, price, and sale price
                        PARAMETERS:     iObj - an item object
                        RETURN: a string containing the HTML code to display the image
                */
                var tContent = "<div class=\"name\"><a href=\"" + iObj.id + ".html\">" + iObj.name2 + "</a></div>";
                tContent += "<div class=\"name2\">" + iObj.name + "</div>";
                if (iObj.saleprice == "-@NULL@-") {
                    tContent += "<div class=\"price\">" + iObj.price + "</div>";
                } else { 
                    tContent += "<div class=pice><span class=\"price\">" + iObj.price + "</span>";
                }
                if (iObj.saleprice != "-@NULL@-") {
                        tContent += "<span class=\"sale-price-bold\">" + iObj.saleprice + "</span></div>";
                }
                tContent += "<div class=\"moreinf\"><a href=\"" + iObj.id + ".html\"><img src=\"http://lib.store.yahoo.net/lib/yhst-20906297561931/moreinf.jpg\" border=\"0\" /></a></div>";
				//tContent += "<a href=\"" + iObj.id + ".html\"><img border=0 href=http://lib.store.yahoo.net/lib/yhst-20906297561931/moreinf.jpg /></a>";
                return tContent;
        }
        
        function displayRandConts( elmId, num, iArr, cols, format ){
                /*
                        displayRandConts - Private - Displays a random set of contents in an existing HTML element
                        PARAMETERS:     elmId - the id for the HTML element in which the random contents will display as a string
                                                num - the number of random items to display as an integer
                                                iArr - items to display from as an array
                                                cols - the number of columns to display in the contents table as an integer
                                                format - the format of the contents table (should be "vertical" or "ell") as a string
                        RETURN: none
                */
                var elm = document.getElementById(elmId);
                if (elm && (iArr.length > 0)) {
                        elm.innerHTML = "";
                        format = format.toString().toLowerCase();
                        var ell = (format == "ell")? true : false;
                        num = (iArr.length < num)? iArr.length : num;
                        cols = (cols > num)? num : cols;
                        rows = Math.ceil(num / cols);
                        iArr = randArr(iArr, num);
                        var tContent = "<table cellpadding=\"0\" cellspacing=\"0\" width=\"100%\" class=\"contents-table\">";
                        for (var i = 0; i < rows; i++) {
                                var prevCells = i * cols;
                                tmpCols = ((prevCells + cols) > num)? num - prevCells : cols;
                                tContent += "<tr>";
                                for (var g = 0; g < tmpCols; g++) {
                                        var currItem = (i * cols) + g;
                                        tContent += "<td class=\"imgCell\">";
                                        tContent += drcImg(iArr[currItem]);
                                        tContent += "</td>";
                                        if (ell) {
                                                tContent += "<td class=\"infoCell\" width=\"" + (100 / cols) + "%\">";
                                                tContent += drcInfo(iArr[currItem]);
                                                tContent += "</td>";
                                        }
                                        if (g < (cols - 1)) {
                                                tContent += "<td class=\"verticalSpacer\" rowspan=\"" + ((ell)? 1 : 2) + "\"></td>";
                                        }
                                }
                                if (!ell) {
                                        tContent += "</tr><tr>";
                                        for (var g = 0; g < tmpCols; g++) {
                                                var currItem = (i * cols) + g;
                                                tContent += "<td class=\"infoCell\" width=\"" + (100 / cols) + "%\">";
                                                tContent += drcInfo(iArr[currItem]);
                                                tContent += "</td>";
                                        }
                                }
                                tContent += "</tr>";
                                if (i < (rows - 1)) {
                                        tContent += "<tr><td class=\"horizontalSpacer\" colspan=\"" + (cols * ((ell)? 3 : 2) - 1) + "\"></td></tr>";
                                }
                        }
                        tContent += "</table>";
                        elm.innerHTML = tContent;
                }
        }
        
        function randArr( iArr, num ) {
                /*
                        randArr - Private - Chooses a random set of items from an array of items
                        PARAMETERS:     iArr - the set of items (as an array) to randomly select from 
                                                num - the number of random items to choose as an integer
                        RETURN: the set of randomized items as an array
                */
                var len = iArr.length;
                if (len > num) {
                        if ((len / 2) > num) {  // Determines which algorithm to use
                                var oArr = iArr;
                                iArr = [];
                                for (var i = 0, j = num; i < j; i++) {
                                        var ran = Math.floor(Math.random() * oArr.length);
                                        iArr.push(oArr[ran]);
                                        oArr.splice(ran,1);
                                }
                                delete oArr;
                        } else {
                                for (var i = 0, j = (len - num); i < j; i++) {
                                        var ran = Math.floor(Math.random() * iArr.length);
                                        iArr.splice(ran,1);
                                }
                        }
                }
                return iArr;
        }
};


