function whirbannerad(id){
var self=this;
this.id=id;
this.type="banner";
this.width=100;
this.height=100;
this.box=null;
this.content="";
this.isloaded=false;
var box=document.createelement("div");
function build(){
if(self.isloaded)return;
box.style.width=self.width+"px";
box.style.height=self.height+"px";
box.style.overflow="hidden";
box.innerhtml=self.content;
if(self.box==null){
var box1=document.createelement("div");
box1.appendchild(box);
document.writeln(box1.innerhtml);
}else{
self.box.appendchild(box);
}
self.isloaded=true;
}
this.load=function(){
build();
}
}
function whirpopupad(id){ //弹出窗口
var self=this;
this.id=id;
this.type="popup";
this.width=100;
this.height=100;
this.left=0;
this.top=0;
this.title="";
this.content="";
this.isloaded=false;
function build(){
if(self.isloaded)return;
var content=self.content;
content=content.replace("\r","").replace("\n","");
var html="
"+self.title+""+content+"";
var pupwin=window.open("","_blank","width="+self.width+",height="+self.height+",top="+self.top+",left="+self.left);
pupwin.document.write(html);
self.isloaded=true;
}
this.load=function(){
build();
}
}
function whirfloatad(id){
//public
this.id=id;
this.type="float";
this.width=100;
this.height=100;
//this.top=0;
//this.left=0;
this.content="";
this.closebutton=true;
this.closebuttonhtml="关闭";
this.timestep=100;
this.isloaded=false;
//private
var self=this;
var timer=null;
var contentdiv=document.createelement("div");
var rootdiv=document.createelement("div");
var xx=yy=vx=vy=0
var vmin=2;
var vmax=5;
var vx=vmin+vmax*math.random();
var vy=vmin+vmax*math.random();
var vr=2;
var ishide=false;
function build(){
if(self.isloaded)return;
if(self.closebutton==true){
var closebutton=document.createelement("span");
//closebutton.href="javascript:;";
closebutton.innerhtml=self.closebuttonhtml;
closebutton.style.cursor="hand";
closebutton.onclick=function(){
self.hide();
}
var closebuttondiv=document.createelement("div");
closebuttondiv.setattribute("align","right");
closebuttondiv.style.position="absolute";
closebuttondiv.style.top="0px";
closebuttondiv.style.right="0px";
closebuttondiv.style.margin="2px";
closebuttondiv.style.padding="2px";
closebuttondiv.style.zindex="999";
closebuttondiv.style.fontsize="12px";
closebuttondiv.appendchild(closebutton);
rootdiv.appendchild(closebuttondiv);
}
contentdiv.innerhtml = self.content;
rootdiv.style.position="absolute";
rootdiv.style.zindex="900";
rootdiv.style.display="none";
rootdiv.style.wordbreak="break-all";
rootdiv.style.width = self.width+"px";
rootdiv.style.height = self.height+"px";
//rootdiv.style.border="1px red solid";
rootdiv.style.overflow="hidden";
//rootdiv.style.left = self.left;
//rootdiv.style.top = self.top;
rootdiv.style.filter= "alpha(style=0,opacity=100,finishopacity=100)";
//rootdiv.style.border = "1px solid #ff0000";
rootdiv.onmouseover=function(){
self.stop();
}
rootdiv.onmouseout=function(){
self.start();
}
rootdiv.appendchild(contentdiv);
document.body.appendchild(rootdiv);
self.isloaded=true;
}
function movediv(){
var pagex=pagew=pagey=pageh=0;
var isie=(document.all)?true:false;
if(!isie){
pagex=window.pagexoffset;
pagew=window.innerwidth;
pagey=window.pageyoffset;
pageh=window.innerheight;
}else{
pagex=window.document.body.scrollleft;
pagew=window.document.body.offsetwidth-8;
pagey=window.document.body.scrolltop;
pageh=window.document.body.offsetheight;
}
xx=xx+vx;
yy=yy+vy;
vx+=vr*(math.random()-0.5);
vy+=vr*(math.random()-0.5);
if(vx>(vmax+vmin)) vx=(vmax+vmin)*2-vx;
if(vx<(-vmax-vmin)) vx=(-vmax-vmin)*2-vx;
if(vy>(vmax+vmin)) vy=(vmax+vmin)*2-vy;
if(vy<(-vmax-vmin)) vy=(-vmax-vmin)*2-vy;
if(xx<=pagex){
xx=pagex;
vx=vmin+vmax*math.random();
}
if(xx>=pagex+pagew-self.width){
xx=pagex+pagew-self.width;
vx=-vmin-vmax*math.random();
}
if(yy<=pagey){
yy=pagey;
vy=vmin+vmax*math.random();
}
if(yy>=pagey+pageh-self.height){
yy=pagey+pageh-self.height;
vy=-vmin-vmax*math.random();
}
rootdiv.style.display="none";
if(!isie){
rootdiv.left = xx;
rootdiv.top = yy;
}else{
rootdiv.style.left = xx;
rootdiv.style.top = yy;
}
rootdiv.style.display="inline";
self.start();
}
this.hide=function(){
rootdiv.style.display="none";
ishide=true;
}
this.stop=function(){
window.cleartimeout(timer);
timer=null;
}
this.start=function(){
if(ishide==false){
timer=window.settimeout(movediv,self.timestep);
}
//movediv();
}
this.load=function(){
build();
self.start();
}
}
function whirscrollad(id){
this.id=id;
this.type="scroll";
this.scroll=true;
this.closeall=true;
this.closebutton=true;
this.closebuttonhtml="关闭";
this.isloaded=false;
var self=this;
var items=[];
var timer=null;
var closedsize=0;
var allclosed=false;
var size=0;
var lastscrolly=0;
function build(){
if(self.isloaded)return;
if(size<1)return false;
for(var i=0;i0){
percent=math.ceil(percent);
}else{
percent=math.floor(percent);
}
followobj.style.top=(y+percent)+"px";
/* if(followobj.offsettop!=(diffy+y)) {
var dy=(diffy+y-followobj.offsettop)*delta;
dy=(dy>0?1:-1)*math.ceil(math.abs(dy));
followobj.style.top=followobj.offsettop+dy;
}*/
}
lastscrolly+=percent;
}
this.load=function(){
build();
timer=window.setinterval(start,100);
//document.body.attachevent("onscroll", start);
}
}
function whirrandplayad(id){
this.id=id;
this.type="randshow";
this.scroll=false;
this.isloaded=false;
}
function whirorderplayad(id){
this.id=id;
this.type="orderchange";
this.scroll=false;
this.isloaded=false;
}
function whirmarqueead(id){
var self=this;
this.id=id;
this.type="banner";
this.scroll=false;
this.width=0;
this.height=0;
this.box=null;
this.isloaded=false;
var html="";
var box=document.createelement("div");
}
function whircurtainad(id){
var self=this;
this.id=id;
this.type="curtain";
this.width=0;
this.height=0;
this.direction="top";
this.autoclosetimer=5;
this.content=null;
this.speed=1;
this.closebutton=true;
this.closebuttonhtml="关闭";
this.parentelement=null;
this.position="absolute";
this.isloaded=false;
this.marginleft="0px";
var html="";
var box=null;
var timer=null;
var autotimer=null;
var delay=5;
var ishide=true;
var isshow=false;
function build(){
if(self.isloaded)return;
var contentdiv=null;
if(self.content!=null && typeof(self.content)=="object"){
box=self.content;
if(self.width==0)self.width=box.offsetwidth;
if(self.height==0)self.height=box.offsetheight;
}else{
box=document.createelement("div");
contentdiv=document.createelement("div");
contentdiv.innerhtml = self.content;
box.appendchild(contentdiv);
if(self.width==0)self.width=100;
if(self.height==0)self.height=100;
}
if(self.direction=="top" || self.direction=="bottom"){
box.style.height="0px";
box.style.width=self.width+"px";
}else{
box.style.width="0px";
box.style.height=self.height+"px";
}
box.style.position=self.position;
box.style.display="none";
box.style.zindex="900";
box.style.wordbreak="break-all";
box.style.overflow="hidden";
box.style.backgroundcolor="#fafafa";
//box.style.border="1px red solid";
box.style.marginleft=self.marginleft;
if(self.closebutton==true){
var closebutton=document.createelement("span");
closebutton.innerhtml=self.closebuttonhtml;
closebutton.style.cursor="hand";
closebutton.onclick=function(){
self.close();
}
var closebuttondiv=document.createelement("div");
closebuttondiv.setattribute("align","right");
closebuttondiv.style.position="absolute";
closebuttondiv.style.top="0px";
closebuttondiv.style.right="0px";
closebuttondiv.style.margin="2px";
closebuttondiv.style.padding="2px";
closebuttondiv.style.zindex="999";
closebuttondiv.style.fontsize="12px";
closebuttondiv.appendchild(closebutton);
box.appendchild(closebuttondiv);
}
if(self.content!=null && typeof(self.content)=="object"){
if(self.parentelement!=null){
self.parentelement.appendchild(box);
}else{
self.parentelement=self.content.parentelement;
}
}else{
if(self.parentelement==null)self.parentelement=document.body;
self.parentelement.appendchild(box);
}
self.isloaded=true;
}
function show(){
ishide=false;
box.style.display="";
if(isshow==true){
if(timer!=null) window.clearinterval(timer);
timer=null;
return ;
}
switch(self.direction){
case "top":
case "bottom":
var h=box.style.height;
h=parseint(h);
h+=delay;
if(h>=self.height){
isshow=true;
h=self.height;
}
box.style.height=h+"px";
if(self.direction=="top"){
box.style.top="0px";
}else{
//var bh=self.parentelement.offsetheight;
//box.style.top=(bh-h)+"px";
box.style.bottom="0px";
}
break;
case "left":
case "right":
var w=box.style.width;
w=parseint(w);
w+=delay;
if(self.direction=="left"){
box.style.left="0px";
}else{
box.style.right="0px";
}
if(w>=self.width){
isshow=true;
w=self.width;
}
box.style.width=w+"px";
break;
}
}
function hide(){
isshow=false;
if(ishide==true){
if(timer!=null) window.clearinterval(timer);
timer=null;
return ;
}
switch(self.direction){
case "top":
case "bottom":
var h=box.style.height;
h=parseint(h);
h-=delay;
if(h<=0){
h=0;
box.style.display="none";
ishide=true;
}
box.style.height=h+"px";
if(self.direction=="top"){
box.style.top="0px";
}else{
//var t=box.style.top;
//t=parseint(t)+delay;
//box.style.top=t+"px";
box.style.bottom="0px";
}
break;
case "left":
case "right":
var w=box.style.width;
w=parseint(w);
w-=delay;
if(w<=0){
w=0;
box.style.display="none";
ishide=true;
}
box.style.width=w+"px";
break;
}
}
this.close=function(){
if(timer!=null) window.clearinterval(timer);
if(autotimer!=null) window.cleartimeout(autotimer);
timer=window.setinterval(hide,self.speed*10);
//hide();
}
this.load=function(){
build();
timer=window.setinterval(show,self.speed*10);
//show();
if(self.autoclosetimer>0)autotimer=window.settimeout(self.close,self.autoclosetimer*1000);
}
}
whirad={
ads:new array(),
adcount:0,
getadcount:function(){
return whirad.adcount;
},
newadvert:function(id,adtype){
var ad=null;
switch(adtype){
case "popup": //弹出窗口
ad=whirad.ads[whirad.adcount++]=new whirpopupad(id);
break;
case "float": //浮动
ad=whirad.ads[whirad.adcount++]=new whirfloatad(id);
break;
case "scroll": //门帘
ad=whirad.ads[whirad.adcount++]=new whirscrollad(id);
break;
case "randplay"://随机显示
ad=whirad.ads[whirad.adcount++]=new whirrandplayad(id);
break;
case "orderplay"://顺序切换
ad=whirad.ads[whirad.adcount++]=new whirorderplayad(id);
break;
case "banner": //固定位置
ad=whirad.ads[whirad.adcount++]=new whirbannerad(id);
break;
case "marquee": //滚动
ad=whirad.ads[whirad.adcount++]=new whirmarqueead(id);
break;
case "curtain"://拉幕式
ad=whirad.ads[whirad.adcount++]=new whircurtainad(id);
break;
}
return ad;
},
new:function(id,adtype){
return whirad.newadvert(id,adtype);
},
load:function(){
for(var i=0;i