(function ($) {
    $.fn.initQuickLinks = function () {
        // Overwrite no javascript css properties
        $('#ql_dropdown').css({ display: 'none', position: 'absolute', right: '12px', top: '22px' });

        $('.sd_dropdown').css({ display: 'none', position: 'relative' });

        $('.result_dropdow`n').css({ display: 'none', position: 'absolute', right: '12px', top: '22px' });

        $('.page_resultNumber dl').each(function () {
            $(this).css({ cursor: 'pointer' });

            $(this).click(function () {
                ShowElement($(this).next());
                return false;
            });
        });

        $('#quicklinks').each(function () {
            $(this).css({ cursor: 'pointer' });

            $(this).click(function () {
                ToggleDisplay($(this), $('#ql_dropdown'));
                return false;
            });
        });

        $('.dropdown_wrapper .dropdown_trigger').each(function () {
            $(this).css({ cursor: 'pointer' });

            $(this).click(function () {
                ToggleDisplay($(this), $(this).siblings('.dropdown_panel'));
                return false;
            });
        });

        // If the body is ever clicked, close the drop down boxes
        $('body').click(function () {
            HideElement($('#ql_dropdown'));
            $('.icon_arrow').removeClass('icon_arrow').addClass('icon-left-arrow');
        });

        $("#quicklinks li a").unbind("click").bind('click', function () { $('#quicklinks').unbind('click'); });

        // for better or worse, this handles both quick links dd and sfware dl dd's <---- JB IS THAT YOU? <----- Nope, but the below is nonsense! grr (ps, this isn't JB)
        function ToggleDisplay(e1, element) {

            //Closes all dropdowns that are open, if there are any drop downs on the page
            for (var i = 0; i < this.AllDropDowns.length; i++) {
                var dd = AllDropDowns[i];
                dd.CloseDropDown();
            }

            if (IsCurrentlyVisible(element)) {
                HideElement(element);
                $('.icon_arrow').removeClass('icon_arrow').addClass('icon-left-arrow');
                $(e1).removeClass('DownArrow').addClass('LeftArrowLeftLine');
                //  $(e1).css("z-index", "1");
            } else {
                $('.DownArrow').parent().css("z-index", "1");
                $('.DownArrow').removeClass('DownArrow').addClass('LeftArrowLeftLine'); // flip all arrows on open boxes to "closed"
                HideElement($('#ql_dropdown'));
                HideElement($('.dropdown'));
                ShowElement(element);
                $('.icon-left-arrow').removeClass('icon-left-arrow').addClass('icon_arrow');
                $(e1).removeClass('.LeftArrowLeftLine').addClass('DownArrow');
            }
        }

        function IsCurrentlyVisible(currentItem) {
            var currentDisplaySetting = $(currentItem).css('display');

            if (currentDisplaySetting == 'block') {
                return true;
            }

            return false;
        }

        function HideElement(element) {
            $(element).css({ display: 'none' });
        }

        function ShowElement(element) {
            $(element).css({ display: 'block' });
        }
    };
})(jQuery);
