var Macro = {start: "__EVENT_TIME_START__", end: "__EVENT_TIME_END__", x: "__OFFSET_X__", y: "__OFFSET_Y__"};
var _clktk, _curl, start_time, end_time;
var good_showid='XuCFhL';
// var good_showid='owHpCc'
//宏替换-1
function mouseDownMacro(el, x, y) {
start_time = Math.round(new Date());
_clktk = el.data('oldclktk');
_curl = el.data("oldcurl");
if (_clktk.indexOf(Macro["start"]) > -1) {
_clktk = _clktk.replace(Macro["start"], start_time);
}
if (_clktk.indexOf(Macro["x"]) > -1) {
_clktk = _clktk.replace(Macro["x"], x);
}
if (_clktk.indexOf(Macro["y"]) > -1) {
_clktk = _clktk.replace(Macro["y"], y);
}
if (_curl.indexOf(Macro["start"]) > -1) {
_curl = _curl.replace(Macro["start"], start_time);
}
if (_curl.indexOf(Macro["x"]) > -1) {
_curl = _curl.replace(Macro["x"], x);
}
if (_curl.indexOf(Macro["y"]) > -1) {
_curl = _curl.replace(Macro["y"], y);
}
el.attr('data-clktk', _clktk);
el.attr('href', _curl);
}
//宏替换-2
function mouseUpMacro(el) {
end_time = Math.round(new Date());
_curl = el.attr("href");
if (_clktk.indexOf(Macro["end"]) > -1) {
_clktk = _clktk.replace(Macro["end"], end_time);
}
if (_curl.indexOf(Macro["end"]) > -1) {
_curl = _curl.replace(Macro["end"], end_time);
}
el.attr('data-clktk', _clktk);
el.attr('href', _curl);
}
function recommend_uid() {
function gethash(s) {
var m;
if (s.indexOf('?') > 0) {
var k = s.split('?')[1];
m = k.length;
} else {
m = 0;
}
return m;
}
var uid = function () {
var d = (new Date() - 0);
var s = window.location.href;
var hash = gethash(s);
uid = "" + d + hash + Math.random() + Math.random() + Math.random() + Math.random();
uid = uid.replace(/\./g, "").substring(0, 32);
return uid;
};
var ml = uid();
var cookie_uid = function () {
$.cookie('cookie_uid_ad', ml, {
expires: 30,
path: '/',
domain: 'news.7654.com'
});
};
if (!$.cookie('cookie_uid_ad')) {
uidm = ml;
cookie_uid(ml);
} else {
uidm = $.cookie('cookie_uid_ad');
}
return uidm;
}
function GetQueryString(name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
var r = window.location.search.substr(1).match(reg);
if (r != null) return unescape(r[2]);
return null;
}
function get360Ad(callback, showId) {
var recommend_url = '//show.g.mediav.com/s',
// var recommend_url = '//ad-test.mediav.com/s',
recommend_showid = showId||good_showid,
recommend_refurl=encodeURIComponent(document.referrer),
recommendk_uid = recommend_uid(),
tck = GetQueryString("tck"),
recommend_param;
tck = tck ? '&tck='+ tck:'';
if (document.location.protocol == "https:") {
recommend_param = 'https://show-g.mediav.com/s' + '?type=1&of=4&newf=2&scheme=https&showids=' + recommend_showid +'&refurl='+recommend_refurl+'&uid=' + recommendk_uid + tck;
} else {
recommend_param = recommend_url + '?type=1&of=4&newf=2&scheme=http&showids=' + recommend_showid +'&refurl='+recommend_refurl+'&uid=' + recommendk_uid + tck;
}
$.ajax({
type: 'get',
url: recommend_param,
dataType: 'jsonp',
jsonp: 'jsonp',
success: function (data) {
if(!data.adspaces){
$.ajax({
type: 'get',
url: recommend_param,
dataType: 'jsonp',
jsonp: 'jsonp',
success: function (data) {
var d = data|| [];
callback && callback(d);
// var pso ={
// timestamp: new Date().getTime(),
// project: location.pathname,
// action:"show",
// p1:'messageFlow',
// p2: recommend_showid,
// p3: !data.ads ? "error": "success",
// p4:"null"
// };
// upload2(pso);
},
error: function () {
var data=[];
callback(data);
}
})
}else{
var d = data|| [];
callback && callback(d);
}
},
error: function () {
var data=[];
callback(data);
}
})
}
/*360曝光*/
var url_scroll = function (arr) {
$.each(arr, function (index, val) {
$('body').append('');
});
};
/*360点击曝光*/
$('body').on('mousedown', '.img_click_gg', function (e) {
var x = Math.floor(e.pageX - $(this).offset().left),
y = Math.floor(e.pageY - $(this).offset().top);
x=x<0?0:x;
y=y<0?0:y;
mouseDownMacro($(this), x, y);
}).on('click', '.img_click_gg', function () {
// upload($(this)[0],'click');
mouseUpMacro($(this));
var str = $(this).attr('data-clktk');
if (str) {
var arr = str.split(',');
$.each(arr, function (index, val) {
$('body').append('');
});
}
});