function whirBannerAD(id){	
    var self=this;
	this.ID=id;
	this.type="Banner";
	this.width=100;
	this.height=100;
	this.box=null;
	this.content="";
	var Box=document.createElement("DIV");
	
	function getAdvert(){		
		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);
		}
	}
	this.load=function(){
		getAdvert();
	}
}

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="";
	
	function open(){
		var content=self.content;
		content=content.replace("\r","").replace("\n","");
		var html="<html><head><title>"+self.title+"</title><style>body{margin:0px;}</style></head><body>"+content+"</body></html>";
		var pupwin=window.open("","_blank","width="+self.width+",height="+self.height+",top="+self.top+",left="+self.left);	
		pupwin.document.write(html);
	}
	this.load=function(){
		open();
	}
}


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;
	
	//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 isInit=false;
	var isHide=false;
	
	function build(){
		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.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);	
		isInit=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(){
		if(!isInit)build();
		self.start();		
	}	
}
function whirScrollAD(id){	//单侧门帘
	this.ID=id;
	this.type="Scroll";
	this.scroll=true;
	
	this.scrollTo=function(){
	}
}

function whirDScrlllAD(id){	
	this.ID=id;
	this.type="DoubleScroll";
	this.scroll=true;
	
	this.scrollTo=function(){
	}
}

function whirRandPlayAD(id){	
	this.ID=id;
	this.type="RandShow";
	this.scroll=false;
}

function whirOrderPlayAD(id){	
	this.ID=id;
	this.type="OrderChange";
	this.scroll=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;
	var HTML="";
	var Box=document.createElement("DIV");
}


function whirAdvert(){
	var self=this;
	var ads=new Array();
	var adCount=0;
	
	function getAdCount(){
		return adCount;
	}
	
	function NewAdvert(id,adType){
		var ad=null;
		switch(adType){
			case "Popup":	
							ad=ads[adCount++]=new whirPopupAD(id);
							break;
			case "Float":	
							ad=ads[adCount++]=new whirFloatAD(id);
					 		break;
			case "Scroll":	
							ad=ads[adCount++]=new whirScrollAD(id);
					 		break;
			case "DScroll":	
							ad=ads[adCount++]=new whirDScrlllAD(id);
					 		break;
			case "RandPlay":	
							ad=ads[adCount++]=new whirRandPlayAD(id);
					 		break;
			case "OrderPlay":	
							ad=ads[adCount++]=new whirOrderPlayAD(id);
					 		break;
			case "Banner":		
							ad=ads[adCount++]=new whirBannerAD(id);
					 		break;
			case "Marquee":		
							ad=ads[adCount++]=new whirMarqueeAD(id);
					 		break;			
		}
		
		return ad;
	}
	
	this.New=function(id,adType){
		return NewAdvert(id,adType);
	}	

}

var whirAD=new whirAdvert();
