 $(document).ready(function() {
        // Wire up show/hide button
        $("#productFinderDisplayButton").mouseover(function() {
            if (!$(this).hasClass("expanded"))
                $(this).addClass("over");
        }).mouseout(function() {
            if (!$(this).hasClass("expanded"))
                $(this).removeClass("over");
        }).click(function() {
            $(this).toggleClass("expanded");
            toggleFinderDisplay();
        });

        // Check the querystring to see if the product finder should be expanded initially
        var exp = $.jqURL.get("prodfinder");
        if (exp != null) {
            // Expand the product finder and scroll to it
            var btn = $("#productFinderDisplayButton");
            if (!btn.hasClass("expanded")) {
                btn.toggleClass("expanded");
                toggleFinderDisplay(function() {
                    $.scrollTo("#productFinderContainer", 1500, { easing: "easeOutSine" });
                });
            }
        }

        // Wire up click event of each checkbox
        $("#productFinderBody input[type='radio']").click(rbClick);

        // Initially hide the body of the product finder
        $("#productFinderBody").hide();
        $("#productFinderBody input[type='radio']").attr("checked", false);
        enableDisableColumns();
    });

    function toggleFinderDisplay(cb) {
        if ($("#productFinderDisplayButton").hasClass("expanded")) {
            // Show the product finder panel
            $("#productFinderBody").slideDown(cb);
        }
        else {
            // Hide the product finder panel
            $("#productFinderBody").slideUp(cb);
        }
    }

    function disableColumn(colno) {
        $("#productFinderCol" + colno).addClass("productFinderColDisabled");
        // Disable and uncheck all radio buttons
        $("#productFinderCol" + colno + " input[type='radio']").attr("disabled", true).attr("checked", false);
    }

    function enableColumn(colno) {
        $("#productFinderCol" + colno).removeClass("productFinderColDisabled");
        // Enable all radio buttons
        $("#productFinderCol" + colno + " input[type='radio']").attr("disabled", false);
    }

    function enableDisableColumns() {
        // If nothing is checked in column 1, disable columns 2 and 3 and disable all result links
        if ($("#productFinderCol1 input[type='radio']:checked").length == 0) {
            disableColumn("2");
            disableColumn("3");
            $(".productFinderLinkDisabled").show();
            $(".productFinderLinkEnabled").hide();
        }
        else {
            enableColumn("2");
        }

        // If column 2 is enabled, but nothing is checked, disable column 3
        if (!$("#productFinderCol2").hasClass("productFinderColDisabled")) {
            if ($("#productFinderCol2 input[type='radio']:checked").length == 0) {
                disableColumn("3");
            }
            else {
                enableColumn("3");
            }
        }
    }

    function enableLink(lnk) {
        $("#lnk" + lnk + " > span.productFinderLinkDisabled").hide();
        $("#lnk" + lnk + " > a.productFinderLinkEnabled").show();
    }

    function disableLink(lnk) {
        $("#lnk" + lnk + " > a.productFinderLinkEnabled").hide();
        $("#lnk" + lnk + " > span.productFinderLinkDisabled").show();
    }

    function rbClick() {
        enableDisableColumns();

        // STEP 1 LOGIC
        // All three Step 1 options enable all five ovens
        enableLink("DeckOven");
        enableLink("HybridConvectionOven");
        enableLink("MiniRotatingRackOven");
        enableLink("RotatingRackOven");
        enableLink("RevolvingTrayOven");

        if ($("#rbRetherm:checked").length > 0) {
            // If Retherm is checked:
            // Enable all ovens and disable columns 2 and 3
            disableColumn("2");
            disableColumn("3");
            disableLink("Proofers");
            disableLink("RetarderProofers");
            disableLink("WaterMeter");
        } else {
            // If either of the other two are checked, enable all links (Water Meter only if Bake From Scratch is checked - this always stays on if BFS is checked)
            if ($("input[@name='Step1']:checked").length > 0) {
                enableLink("Proofers");
                enableLink("RetarderProofers");
                if ($("#rbBakeFromScratch:checked").length > 0) {
                    enableLink("WaterMeter");
                } else {
                    disableLink("WaterMeter");
                }
                enableColumn("2");
            } else {
                // Disable columns 2 and 3
                disableColumn("2");
                disableColumn("3");
            }
        }

        // STEP 2 LOGIC
        // Selecting Bread or Bagels keeps everything.
        // Selecting Sweet Goods or Meringues/Custards removes Proofers and Retarder/Proofers.
        if ($("#rbSweetGoods:checked").length > 0 || $("#rbMeringues:checked").length > 0) {
            disableLink("Proofers");
            disableLink("RetarderProofers");
        }
        // Selecting Sweet Goods also removes Deck Ovens and Revolving Tray Ovens.
        if ($("#rbSweetGoods:checked").length > 0) {
            disableLink("DeckOven");
            disableLink("RevolvingTrayOven");
        }
        // Selecting Deep Dish Pizzas keeps only Revolving Tray and Deck Ovens and disallows step 3
        if ($("#rbDeepDish:checked").length > 0) {
            disableLink("HybridConvectionOven");
            disableLink("MiniRotatingRackOven");
            disableLink("RotatingRackOven");
            disableLink("Proofers");
            disableLink("RetarderProofers");
            disableColumn("3");
        }
        // Selecting Panned Foods keeps only Hybrid Convection and Mini Rotating Rack Ovens and disallows step 3
        if ($("#rbPanned:checked").length > 0) {
            disableLink("DeckOven");
            disableLink("RotatingRackOven");
            disableLink("RevolvingTrayOven");
            disableLink("Proofers");
            disableLink("RetarderProofers");
            disableColumn("3");
        }

        // STEP 3 LOGIC
        // If small batches, Mini Rotating Rack and Hybrid Convection Oven only. Allow proofers to remain selected.
        if ($("#rbSmallBatches:checked").length > 0) {
            disableLink("DeckOven");
            disableLink("RotatingRackOven");
            disableLink("RevolvingTrayOven");
        }
        else if ($("#rbLargeBatches:checked").length > 0) {
            disableLink("MiniRotatingRackOven");
            disableLink("HybridConvectionOven");
        }
    }