var timespan = navigator.userAgent.indexOf("Firefox") > 0 ? 15 : 10;
var AdConfig = 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, obj2, width, height, top, side, autoClose, showButton)
{
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";
}
}
if (showButton)
{
obj2.onclick = function()
{
window.clearInterval(interval);
obj.style.display = "none";
}
}
}
function AdHangLeft(obj, obj2, top, autoClose, showButton)
{
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";
}
}
if (showButton)
{
obj2.onclick = function()
{
window.clearInterval(interval);
obj.style.display = "none";
}
}
}
function AdHangRight(obj, obj2, top, autoClose, showButton)
{
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";
}
}
if (showButton)
{
obj2.onclick = function()
{
window.clearInterval(interval);
obj.style.display = "none";
}
}
}
function AdPrepare(id, title, url, mode, pic, width, height, top, side, autoClose, showButton)
{
if (!AdConfig)
AdConfigInit();
var content = AdContent(url, pic, width, height);
if (mode == "popup")
{
AdPopup(id, title, content, width, height, top, side, autoClose);
return;
}
var html = "";
if (showButton == 1)
{
html = html + "
";
}
else if (showButton == 2)
{
html = html + "
";
}
html = html + content + "";
document.writeln(html);
var obj = document.getElementById("adver_" + id);
var obj2 = document.getElementById("shut_" + id);
switch(mode)
{
case "float":
AdFloat(obj, obj2, width, height, top, side, autoClose, showButton);
break;
case "hangL":
AdHangLeft(obj, obj2, top, autoClose, showButton);
break;
case "hangR":
AdHangRight(obj, obj2, top, autoClose, showButton);
break;
}
}
function AdContent(url, pic, width, height)
{
var picType = pic.substr(pic.lastIndexOf(".") + 1).toLowerCase();
var content;
if (picType == "swf")
{
content = "";
if (url != "")
content = "
" + content;
else
content = "
" + content;
}
else
{
content = "
";
if (url != "") content = "" + content + "";
}
return content;
}