var _____WB$wombat$assign$function_____=function(name){return (self._wb_wombat && self._wb_wombat.local_init && self._wb_wombat.local_init(name))||self[name];};if(!self.__WB_pmw){self.__WB_pmw=function(obj){this.__WB_source=obj;return this;}}{
let window = _____WB$wombat$assign$function_____("window");
let self = _____WB$wombat$assign$function_____("self");
let document = _____WB$wombat$assign$function_____("document");
let location = _____WB$wombat$assign$function_____("location");
let top = _____WB$wombat$assign$function_____("top");
let parent = _____WB$wombat$assign$function_____("parent");
let frames = _____WB$wombat$assign$function_____("frames");
let opens = _____WB$wombat$assign$function_____("opens");
const main = function(){
    const base_url = window["__tablelabs_base_url"] || 'https://api.tablelabs.com';

    const isIE = (function (ua) {
        return ua.indexOf('MSIE ') > 0 || ua.indexOf('Trident/') > 0 || ua.indexOf('Edge/') > 0
    })(window.navigator.userAgent);

    (function($){
        $(document).ready(function(){
            if($("div[id^='tableLabs-']").first().prop('class') !== 'initialized'){
               $('head').append("<link href='//fonts.googleapis.com/css?family=Titillium Web' rel='stylesheet'>");
            };

            const trackButtonClick = function(itemId) {
                $.ajax({
                    type: "GET",
                    url: base_url + "/public/items/" + itemId  + "/track/",
                });
            };
            const handleClick = function(event) {
                event.preventDefault();
                const button = $(this).closest('tr').find('a[id^="button-"]');
                window.open(button.prop('href'), '_blank');
                const itemId = button.attr('id').split("-")[1];
                trackButtonClick(itemId);
            };

            $("div[id^='tableLabs-']").each(function(index){
                if ($(this).prop('class') !== 'initialized') {
                    const chartDiv = $(this);
                    const chartUid = chartDiv.attr("id").split("-")[1];
                    chartDiv.prop('class', 'initialized');

                    $.ajax({
                        type: "GET",
                        url: base_url + "/public/charts/" + chartUid  + "/embed/",
                    }).done((function (chartDiv, chartUid) { return function(response) {
                        chartDiv.append(response);
                        const resize = function() {
                            chartDiv.find('#top-pick-border-' + chartUid).css('width', chartDiv.find('table').width());
                            if (isIE) {
                                chartDiv.find('#top-pick-border-' + chartUid).css('height', chartDiv.find('#top-pick-row-' + chartUid).height());
                            }
                        }
                        resize()
                        $(window).bind("resize", resize)
                        chartDiv.find('a[id^="button-"]').click(function() {
                            const itemId = $(this).attr('id').split("-")[1];
                            trackButtonClick(itemId);
                        });
                        chartDiv.find('.tl-image').find('a').click(handleClick);
                        chartDiv.find('.tl-price').find('a').click(handleClick);
                        chartDiv.find('.tl-title').find('a').click(handleClick);
                    }})(chartDiv, chartUid));
                }
            });
        });
    })(jQuery);
};

var waitForjQuery = function() {
    if (window.hasOwnProperty("jQuery")) {
        main();
    } else {
        setTimeout(waitForjQuery, 300);
    }
}
waitForjQuery();

}