//判断是否有浮动广告
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 FrontFloatAdvertise_show={

//对广告中文字添加商品或者商品分类链接
wrapLinks:function (s) {
			var p = /(<a v="1".*?>)(.*)(<\/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("<a") >= 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;
				}
	},
	//设置浮动广告根据浏览器显示位置，显示浮动广告当前位置。
	$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 (/close/.test(_e.className)) _e.onclick = function() {
			var p = this;
			while ((p=p.parentNode) && !/FrontFloatAdvertise_show/.test(p.className));
			if (p) p.parentNode.removeChild(p);
		};
	}
  }
}

//浏览器兼容不同浏览器用不同方法		
if (!window.addEventListener && window.attachEvent) {
	window.addEventListener = function(e, f, c) {
		window.attachEvent('on' + e, f, c||false);
	}
}

//构造浮动广告
window.addEventListener("load", function() {
	var cs = document.getElementsByTagName("div");
	for (var i=0, c; c=cs[i]; i++) {
		if (c.className.indexOf("FrontFloatAdvertise_show") >= 0) {
			FrontFloatAdvertise_show.$float(c, parseInt(c.getAttribute('left') || 0), parseInt(c.getAttribute('top') || 0));
		}
	}
}, false);

}
