//判断是否有浮动广告
if (!window.$initialized_advertisemanage_float) {
window.$initialized_advertisemanage_float = true;
//取当前浏览器显示left
window.getscrollleft = window.getscrollleft || function(){
return this.pagexoffset || document.documentelement.scrollleft || document.body.scrollleft;
};
//取当前浏览器显示top
window.getscrolltop = window.getscrolltop || function(){
return this.pageyoffset || document.documentelement.scrolltop || document.body.scrolltop;
};
//取当前浏览器显示width
window.getwidth = window.getwidth || function() {
return this.innerwidth || document.documentelement.clientwidth || document.body.clientwidth;
};
//取当前浏览器显示height
window.getheight = window.getheight || function() {
return this.innerheight || document.documentelement.clientheight || document.body.clientheight;
};
//浮动广告js方法定义
var frontadv_float01={
//对广告中文字添加商品或者商品分类链接 参数 s:html链接字符串
wraplinks:function (s) {
var p = /()(.*)(<\/a>)/;
var prefix, sufix;
if (p.test(s)) {
prefix = regexp.$1;
sufix = regexp.$3;
var ctn = regexp.$2;
var m, r = "", text, l = 0, p = /<\/?a.*?>/img, stack = [];
while (m = p.exec(ctn)) {
if (m[0].indexof("= 0) {
stack.push(m[0]);
text = ctn.substring(l, m.index);
l = p.lastindex;
if (text) r += prefix + text + sufix;
} else {
text = ctn.substring(l, m.index);
r += stack.pop() + text + m[0];
l = p.lastindex;
}
}
text = ctn.substring(l);
if (text) r += prefix + text + sufix;
return r;
} else {
return s;
}
},
//页面加载后对每一个浮动广告层进行重新定位及相关设置
$init:function () {
var cs = document.getelementsbytagname("div");
for (var i=0, c; c=cs[i]; i++) {
if (c.classname.indexof("frontadv_float01-default") >= 0) {
frontadv_float01.$float(c, parseint(c.getattribute('left') || 0), parseint(c.getattribute('top') || 0));
}
}
},
//设置浮动广告根据浏览器显示位置,显示浮动广告当前位置。 参数 el:div对象 x:div左位置 y:div上部位置
$float:function (el, x, y) {
var reversex = false, reversey = false;
var fn = function() {
el.style.left = x + window.getscrollleft() + "px";
el.style.top = y + window.getscrolltop() + "px";
x += (reversex ? -1 : 1);
y += (reversey ? -1 : 1);
if (x < 0) {
x = 0;
reversex = false;
}
var right = window.getwidth() - el.offsetwidth;
if (x > right) {
x = right;
reversex = true;
}
if (y < 0) {
y = 0;
reversey = false;
}
var bottom = window.getheight() - el.offsetheight;
if (y > bottom) {
y = bottom;
reversey = true;
}
}
el.timer = setinterval(fn, 30);
el.onmouseover = function() {clearinterval(el.timer);};
el.onmouseout = function() {el.timer = setinterval(fn, 30);};
el.style.position = "absolute";
var closes = el.parentnode.getelementsbytagname("div");
for (var i=0, _e; _e=closes[i]; i++) {
if (/shut/.test(_e.classname)) _e.onclick = function() {
var p = this;
while ((p=p.parentnode) && !/frontadv_float01-default/.test(p.classname));
if (p) p.parentnode.removechild(p);
};
}
}
}
}