(function($) {
    $.fn.initQuickLinks = function() {
        // Overwrite no javascript css properties
        $('#ql_dropdown').css({ display: 'none', position: 'absolute', right: '12px', top: '22px' });

        $('.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($('#ql_dropdown'));
                return false;
            });
        });

        $('.dropdown_wrapper .dropdown_trigger').each(function() {
            $(this).css({ cursor: 'pointer' });

            $(this).click(function() {
                ToggleDisplay($(this).siblings('.dropdown_panel'));
                return false;
            });
        });

        // If the body is ever clicked, close the drop down boxes
        $('body').click(function() {
            HideElement($('#ql_dropdown'));
            HideElement($('.dropdown'));
            $('.icon_arrow').removeClass('icon_arrow').addClass('icon-left-arrow');
        });

        $("#quicklinks li a").unbind("click").bind('click', function() { $('#quicklinks').unbind('click'); });

        function ToggleDisplay(element) {
            if (IsCurrentlyVisible(element)) {
                HideElement(element);
                $('.icon_arrow').removeClass('icon_arrow').addClass('icon-left-arrow');
            } else {
                ShowElement(element);
                $('.icon-left-arrow').removeClass('icon-left-arrow').addClass('icon_arrow');
            }
        }

        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);
