var timespan = navigator.useragent.indexof("firefox") > 0 ? 15 : 10; var adconfig = false; var hasbutton = false; //是否在右上角显示关闭按钮 function addevent(obj, eventtype, func) { if (obj.addeventlistener) { obj.addeventlistener(eventtype, func, false); } else if (obj.attachevent) { obj.attachevent("on" + eventtype, func); } } function adconfiginit() { adconfig = new object(); adconfig.left = 0; adconfig.top = 0; adconfig.width = 0; adconfig.height = 0; adconfig.scroll = function() { if (document.documentelement && document.documentelement.scrollleft) { adconfig.left = document.documentelement.scrollleft; } else if (document.body) { adconfig.left = document.body.scrollleft; } if (document.documentelement && document.documentelement.scrolltop) { adconfig.top = document.documentelement.scrolltop; } else if (document.body) { adconfig.top = document.body.scrolltop; } } adconfig.resize = function() { if (document.documentelement && document.documentelement.clientheight && document.body && document.body.clientheight) { adconfig.width = (document.documentelement.clientwidth > document.body.clientwidth) ? document.body.clientwidth : document.documentelement.clientwidth; adconfig.height = (document.documentelement.clientheight > document.body.clientheight) ? document.body.clientheight : document.documentelement.clientheight; } else if (document.documentelement && document.documentelement.clientheight) { adconfig.width = document.documentelement.clientwidth; adconfig.height = document.documentelement.clientheight; } else if (document.body) { adconfig.width = document.body.clientwidth; adconfig.height = document.body.clientheight; } } adconfig.scroll(); adconfig.resize(); addevent(window, "scroll", adconfig.scroll); addevent(window, "resize", adconfig.resize); } function adpopup(id, title, content, width, height, top, side, autoclose) { var popup = window.open("", "win" + id, "width=" + width + ", height=" + height + ", top=" + top + ", left=" + side); popup.document.write(""); popup.document.write(title); popup.document.write(""); popup.document.write(content); popup.document.write(""); } function adfloat(obj, width, height, top, side, autoclose) { var directx = 1; var directy = 1; obj.move = function() { if (side + width >= adconfig.left + adconfig.width) { side = adconfig.left + adconfig.width - width; directx = -1; } else if (side <= adconfig.left) { side = adconfig.left; directx = 1; } if (top + height >= adconfig.top + adconfig.height) { top = adconfig.top + adconfig.height - height; directy = -1; } else if (top <= adconfig.top) { top = adconfig.top; directy = 1; } side += directx; top += directy; obj.style.left = side + "px"; obj.style.top = top + "px"; } var interval = window.setinterval(obj.move, timespan); obj.onmouseover = function() { window.clearinterval(interval); } obj.onmouseout = function() { interval = window.setinterval(obj.move, timespan); } if (autoclose) { obj.onclick = function() { window.clearinterval(interval); obj.style.display = "none"; } } } function adhangleft(obj, top, autoclose) { obj.move = function() { var t = parseint(obj.style.top, 10); if (t + 5 < adconfig.top + top) { obj.style.top = (t + 5) + "px"; } else if (t - 5 > adconfig.top + top) { obj.style.top = (t - 5) + "px"; } } var interval = window.setinterval(obj.move, timespan); if (autoclose) { obj.onclick = function() { window.clearinterval(interval); obj.style.display = "none"; } } } function adhangright(obj, top, autoclose) { obj.move = function() { var t = parseint(obj.style.top, 10); if (t + 5 < adconfig.top + top) { obj.style.top = (t + 5) + "px"; } else if (t - 5 > adconfig.top + top) { obj.style.top = (t - 5) + "px"; } } var interval = window.setinterval(obj.move, timespan); if (autoclose) { obj.onclick = function() { window.clearinterval(interval); obj.style.display = "none"; } } } function adprepare(id, title, url, mode, pic, width, height, top, side, autoclose) { if (!adconfig) adconfiginit(); var content = adcontent(url, pic, width, height); if (mode == "popup") { adpopup(id, title, content, width, height, top, side, autoclose); return; } document.writeln("" + content + ""); var obj = document.getelementbyid("adver_" + id); switch(mode) { case "float": adfloat(obj, width, height, top, side, autoclose); break; case "hangl": adhangleft(obj, top, autoclose); break; case "hangr": adhangright(obj, top, autoclose); break; } } function adcontent(url, pic, width, height) { var pictype = pic.substr(pic.lastindexof(".") + 1).tolowercase(); var content; if (pictype == "swf") { content = ""; if (url != "") if (hasbutton) content = "" + content; else content = "" + content; else content = "" + content; } else { content = ""; if (url != "") if (hasbutton) content = "" + content + ""; else content = "" + content + ""; } return content; }