if(typeof window.CCompareTips === "undefined"){//begin double-inclusion prevention

    window.CCompareTips = new function() {
        /*===========*
        * CONSTANTS *
        *===========*/

        var states = ['nothingSelected', 'oneSelected', 'multiSelected'];
        var maxChecked = 10;

        /*===========*
        * VARIABLES *
        *===========*/

        var jq_infoTip = undefined;
        var numChecked = 0;

        /*===========*
        * ACCESSORS *
        *===========*/

        function updateState() {
            if (arguments.length === 0) {
                numChecked = $(".productList-compare input[type='checkbox']:checked").size();
            }
            else {
                numChecked += arguments[0];
            }

            var atLeast = numChecked < 2 ? numChecked : 2;

            jq_infoTip.removeClass(jq_infoTip.checkState);
            jq_infoTip.checkState = states[atLeast];
            jq_infoTip.addClass(jq_infoTip.checkState);

            if (atLeast === 2) {
                jq_infoTip.find('span.numChecked').html(numChecked);
            }
        }

        function moveToBox(el) {
            if (jq_infoTip.parent().get(0) === el)
                return;

            jq_infoTip.remove();
            jq_infoTip.appendTo(el);
        }

        function showTip() {
            jq_infoTip.addClass('onhover');
        }

        function hideTip() {
            jq_infoTip.removeClass('onhover');
        }

        /*=================*
        * EVENT RESPONSES *
        *=================*/

        function compareOver(ev) {
            if ($(this).filter("div.productList-compare").size() === 0)
                return;

            moveToBox(this);
            showTip();
        }

        function compareAway(ev) {
            hideTip();
        }

        function boxChecked(ev) {
            updateState(this.checked ? 1 : -1);
        }

        function linkClicked(ev) {
            //do nothing, for now
        }

        /*============*
        * INITIALIZE *
        *============*/

        function buildInfoTip() {
            jq_infoTip = $("body").append('<div id="compareInfoTip" class="none"></div>').find("#compareInfoTip").eq(0);

            jq_infoTip.append('<div class="compareState nothingSelected">Check the box next to each product you want to compare.</div>');
            jq_infoTip.append('<div class="compareState oneSelected">You can compare up to ' + maxChecked + ' products. (Please select at least one more to compare.)</div>');
            jq_infoTip.append('<div class="compareState multiSelected">When you\'re ready, click the "compare" link.<br />(<span class="numChecked">' + (maxChecked - 2) + '</span> currently checked, maximum of ' + maxChecked + '.)</div>');
        }

        function init() {
            var boxes = $(".productList-compare");

            if (boxes.size() === 0)
                return;
            // If compare checkbox exists
            if($(".productList-compare:has(input[type='checkbox'])").length > 0) {
                buildInfoTip();
                updateState();
                moveToBox(boxes.get(0));
                boxes.hover(compareOver, compareAway);
                boxes.find("input[type='checkbox']").click(boxChecked); //IE doesn't fire .change() until .blur() >:-(
                boxes.find("a").click(linkClicked);
            }
        }

        this.init = init;
    };

//$(CCompareTips.init);

}//end double-inclusion prevention
