(function($) {
    // If not logged in, enable register reminder
    if (Drupal.settings.member && definitions && !definitions.TransientKey) {
        Drupal.settings.member.remind_enabled = true;
    }

    // Enable flash sale ad
    if (Drupal.settings.rawtstore) {
        Drupal.settings.rawtstore.flash_enabled = true;
    }

    $(document).ready(function() {
        // Use fancybox for attachments
        if ($.fn.fancybox) {
            $('.Vanilla .Comment .Attachment a').on('click', function() {
                var $link = $(this);
                var $attach = $link.closest('.Attachment');
                var $previewLink = $('.FilePreview > a', $attach);
                var $img = $previewLink.children('img:first');

                if ($img.length > 0) {
                    $.fancybox.open([{ src: $previewLink.attr('href') }]);
                    return false;
                }
            });
        }

        var $filterMenu = $('ul.FilterMenu');

        // Add class to unanswered questions so we can style differently when unanswered
        $('.QnA-UnansweredQuestions', $filterMenu).each(function() {
            var $item = $(this);
            var $count = $('.Count', $item);

            $count.addClass('Progress');

            $('.Count:not(.Progress)', $item).livequery(function() {
                if (parseInt(this.innerHTML)) {
                    $item.addClass('ActiveQuestions');
                }

                $('.Count:not(.Progress)', $item).expire();
            });
        });
    });
})(jQuery);
