/*;var _tmr = window._tmr || (window._tmr = []);
_tmr.push({id: "2761531", type: "pageView", start: (new Date()).getTime(), pid: "USER_ID"});
(function (d, w, id) {
  if (d.getElementById(id)) return;
  var ts = d.createElement("script"); ts.type = "text/javascript"; ts.async = true; ts.id = id;
  ts.src = "https://top-fwz1.mail.ru/js/code.js";
  var f = function () {var s = d.getElementsByTagName("script")[0]; s.parentNode.insertBefore(ts, s);};
  if (w.opera == "[object Opera]") { d.addEventListener("DOMContentLoaded", f, false); } else { f(); }
})(document, window, "topmailru-code");*/

; var _tmr = window._tmr || (window._tmr = []), tmr_pixel_id = 3291957;
_tmr.push({ id: tmr_pixel_id, type: "pageView", start: (new Date()).getTime() });
(function (d, w, id) {
    if (d.getElementById(id)) return;
    var ts = d.createElement("script"); ts.type = "text/javascript"; ts.async = true; ts.id = id;
    ts.src = "https://top-fwz1.mail.ru/js/code.js";
    var f = function () { var s = d.getElementsByTagName("script")[0]; s.parentNode.insertBefore(ts, s); };
    if (w.opera == "[object Opera]") { d.addEventListener("DOMContentLoaded", f, false); } else { f(); }
})(document, window, "tmr-code");

; (function ($) {
    var pagetype = window.pagetype || "";

    switch (pagetype) {
        case 'home':
            window._tmr.push({
                type: "reachGoal",
                id: tmr_pixel_id,
                goal: "homePage"
            });
            console.log("mailru_event.js Home");
            break;

        case 'product':
            window._tmr.push({
                type: 'itemView',
                productid: pageid,
                pagetype: 'product',
                list: targetMailFeedId,
                totalvalue: pricenum
            });

            window._tmr.push({
                type: "reachGoal",
                id: tmr_pixel_id,
                value: pricenum,
                goal: "viewProduct",
                params: {
                    product_id: pageid
                }
            });
            console.log("mailru_event.js viewProduct");
            break;
        
        case 'purchase':
            window._tmr.push({
                type: "reachGoal",
                id: tmr_pixel_id,
                value: totalvalue,
                goal: "purchase",
                params: {
                    product_id: productid
                }
            });
            console.log("mailru_event.js Purchase _tmr=" +  JSON.stringify(window._tmr));
        break;
    }

    $(document).on('click', '.btn-buy', function(e){
		window._tmr.push({ 
            type: "reachGoal", 
            id: tmr_pixel_id, 
            value: parseInt(jQuery(this).data("price")), 
            goal: "addToCart", 
            params: { 
                product_id: jQuery(this).data("productid")
            }
        });

        console.log("mailru_event.js addToCart _tmr=" + JSON.stringify(window._tmr));
	});

    $(document).on('click', '.favorites img', function(e){
        var value;

        if($('.yr-category-app').length){
            let parent = $(this).closest('.product-cell');
            value = parseInt($('.btn-buy', parent).data(price));
        }else{
            value = pricenum;
        }

		window._tmr.push({
            type: 'reachGoal',
            id: tmr_pixel_id,
            value: value,
            goal: 'favorites',
            params: {
                product_id: jQuery(this).data("product")
            }
        });

        console.log("mailru_event.js favorites _tmr=" + JSON.stringify(window._tmr));
	});

}(jQuery));