
var hideRandomCategories = function () {
    // Get all the Lis
    var lis = $('#right-content li').not('.current');

    // randomly filter out 9 categories
    for (i = 0; i < 9; i++) {
        index = Math.floor(Math.random() * lis.length);
        lis = lis.not(':eq(' + index + ')');
    }

    // hide the rest
    lis.hide();

};

var showAllCategories = function () {
    $('#right-content li').show();
}


var categoryClickHandler = (function () {
    visibleSwitch = false;
    return function () {
        if (visibleSwitch) {
            showAllCategories();
            $('a.viewall').html("Shrink category list");
        } else {
            hideRandomCategories();
            $('a.viewall').html("View all categories");
        }

        visibleSwitch = !visibleSwitch;
        return false;
    };
})();

$(function () {
    $('a.viewall').click(categoryClickHandler).trigger('click');
})