﻿(function ($) {
    $(function () {
        if ($('#commentNav').length > 0) {
            // submit comment navigation 
            $('#commentTypeNav a').click(function () {
                $('#commentTypeNav').removeAttr('class').addClass($(this).parent('li').attr('id'));
                commentType();
            });

            commentType();


            // filter comment navigation
            $('#commentNav .comment_filter').click(function () {
                if (!$('a', this).hasClass('inactive')) {
                    $('#commentNav .comment_filter a.active').removeClass('active');
                    $('a', this).addClass('active');
                    var showComments = $(this).attr('id');
                    filterComments(showComments);
                }
            });

            $('.comment').addClass('visible'); -

            colorCommentBGs();

            if ($('.comment.review_filter').length == 0) $('#review_filter a').addClass('inactive');
            if ($('.comment.variation_filter').length == 0) $('#variation_filter a').addClass('inactive');
            if ($('.comment.general_filter').length == 0) $('#general_filter a').addClass('inactive');
        }
    });


})(jQuery);

function commentType(init) {
    if ($('#commentTypeValue') != null && $('#commentTypeNav') != null && $('#commentTypeNav').attr('class') != null) {
        $('#commentTypeValue').val($('#commentTypeNav').attr('class').split('_')[0]);
        
        if ($('#commentTypeNav').attr('class') == 'review_tab') 
            $('#commentRating').show();
        else 
            $('#commentRating').hide();
    }
}

function colorCommentBGs(){
    var bgSwitch = 0;
    $('.comment').removeClass('comment_tan_bg').each(function(){
        if( $(this).hasClass('visible') ){
            bgSwitch++;
            if(bgSwitch == 1){
              $(this).addClass('comment_tan_bg');
            } else {
               bgSwitch = 0;
            } 
        }
    });
}

function filterComments(showComments){
    $('.comment').each(function(){
        if( $(this).hasClass( showComments ) ) $(this).removeClass('hidden').addClass('visible');
        else $(this).addClass('hidden').removeClass('visible');
    });
    colorCommentBGs();
}
