$(document).ready(function() {
    var recommedPtds = {};
    $(document).on('click', ".recommendthis", function() {
        var productid = $(this).attr('product_id');
        var clickedDiv = $(this);
        if (productid > 0) {
            if (typeof recommedPtds[productid] != 'undefined') {
                data = recommedPtds[productid];
                $('#recommend-outer-div').html(data.html);
                $('.recommendthis').removeClass('active');
                clickedDiv.addClass('active');
                if (data.count > 5)
                    setRecommendationSlider(!0);
                else setRecommendationSlider(!1)
            } else {
                $.ajax({
                    type: 'POST',
                    beforeSend: function() {},
                    data: 'productid=' + productid,
                    dataType: 'json',
                    url: GLOBAL_BASE_PATH + "/product/ajaxrecommendproducts/",
                    success: function(data) {
                        recommedPtds[productid] = data;
                        $('#recommend-outer-div').html(data.html);
                        $('.recommendthis').removeClass('active');
                        clickedDiv.addClass('active');
                        if (data.count > 5)
                            setRecommendationSlider(!0);
                        else setRecommendationSlider(!1)
                    }
                })
            }
        }
    });
    if ($('#recent-viewed').length) {
        $.ajax({
            type: 'POST',
            data: 'currentProductID=' + detailPageProductID,
            beforeSend: function() {},
            url: GLOBAL_BASE_PATH + "/product/ajaxrecentlyviewed/",
            success: function(data) {
                $('.recommend').html(data);
                if ($.trim(data) != 0) {
                    setRecentViewedSlider();
                    $(".recommendthis:first").click()
                }
            }
        })
    }
});

function setRecommendationSlider(controls) {
    $(".recommend-slick").not('.slick-initialized').slick({
        infinite: !1,
        speed: 700,
        prevArrow: '<span class="icon-left-thin sli-arrow left"></span>',
        nextArrow: '<span class="icon-right-thin sli-arrow right"></span>',
        slidesToShow: 4,
        slidesToScroll: 4,
        responsive: [{
            breakpoint: 1280,
            settings: {
                slidesToShow: 3,
                slidesToScroll: 3,
            }
        }, {
            breakpoint: 992,
            settings: {
                slidesToShow: 2,
                slidesToScroll: 2,
            }
        }, {
            breakpoint: 768,
            settings: {
                slidesToShow: 3,
                slidesToScroll: 3
            }
        }, {
            breakpoint: 600,
            settings: {
                slidesToShow: 2,
                slidesToScroll: 2
            }
        }, {
            breakpoint: 361,
            settings: {
                slidesToShow: 2,
                slidesToScroll: 2
            }
        }]
    })
}

function setRecentViewedSlider() {
    $('.recommend-slick-left').not('.slick-initialized').slick({
        vertical: !0,
        infinite: !1,
        speed: 300,
        prevArrow: '<span class="icon-arrow-bold-left sli-arrow top"></span>',
        nextArrow: '<span class="icon-arrow-bold-right sli-arrow bottom"></span>',
        slidesToShow: 4,
        slidesToScroll: 4,
        responsive: [{
            breakpoint: 768,
            settings: {
                vertical: !1,
                slidesToShow: 3,
                slidesToScroll: 3,
                prevArrow: '<span class="icon-left-thin sli-arrow left"></span>',
                nextArrow: '<span class="icon-right-thin sli-arrow right"></span>',
            }
        }, {
            breakpoint: 650,
            settings: {
                vertical: !1,
                slidesToShow: 2,
                slidesToScroll: 2,
                prevArrow: '<span class="icon-left-thin sli-arrow left"></span>',
                nextArrow: '<span class="icon-right-thin sli-arrow right"></span>',
            }
        }, {
            breakpoint: 450,
            settings: {
                vertical: !1,
                slidesToShow: 1,
                slidesToScroll: 1,
                prevArrow: '<span class="icon-left-thin sli-arrow left"></span>',
                nextArrow: '<span class="icon-right-thin sli-arrow right"></span>',
            }
        }, ]
    })
}