//*****************漂浮广告显示类******************
//* 用法:
//* var adver=new adverClass
//* adver.setObjName("adver"); //这句不能setTime所以没有用
//* adver.setDivID(1); //这句可以不用
//* adver.setImageType(1); //设为0时或不写这句时则是普通图片，1则为Flash动画文件
//* adver.setImagePX(299,87); //设置图片的宽度与高度
//* adver.showAdver("http://www.yourdomain.com/target.swf","http://www.yourdomain.com/' target="_blank" >http://www.yourdomain.com/target.swf","http://www.yourdomain.com/","Text");
//* var adver1=new adverClass();
//* adver1.showAdver("img.gif","http://www.yourdomain.com/","Text");
//* setTimer();
//* //因为类里不能写setTime所以只好拿出来写-_-##(VBS脚本竟然可以。我倒)
//* function setTimer(){
//* adver.floatScroll();
//* adver1.floatScroll();
//* setTimeout("setTimer()",80);
//* }
//***********************************************
function adverClass(){
var objName="";
var imageType=0;
var imageWidth=imageHeight=0;
var iTop=iLeft=0;
var topFlag=leftFlag=false;
var divID=0,objDiv=null;
var offWidth=offHeight=0;
var width=document.body.clientWidth;
var height=document.body.clientHeight;
var delay=30; //时间的延迟值
var topStep=2,leftStep=3; //一步跨多少
var inter;
//此处是当外部不设置divID的值能够确保层的ID是唯一
divID=Math.round(Math.random()*100000)
//广告的类型 0=普通图片 1=Flash广告图片
this.setImageType=function(sType){
if(sType!=1&&sType!=0){sType=0;}
imageType=sType;
}
//外部调用的变量名
this.setObjName=function(sName){objName=sName;}
//广告图片的高度与宽度
this.setImagePX=function(iWidth,iHeight){
if(!isNaN(iWidth)){
imageWidth=iWidth;
}else{
imageWidth=0;
}
if(!isNaN(iHeight)){
imageHeight=iHeight;
}else{
imageHeight=0;
}
}
//设置广告所在层的ID值
this.setDivID=function(iDiv){divID=iDiv;}

//主函数，显示广告代码
this.showAdver=function(adImgSrc,adHref,adTitle){
if(imageType==0){
showImageHtml(adImgSrc,adHref,adTitle);
}else{
showFlashHtml(adImgSrc,adHref,adTitle);
}
eval("objDiv=document.all.img"+divID+";");
//取得图片的宽度
offWidth=objDiv.offsetWidth;
offHeight=objDiv.offsetHeight;
//随机显示广告的开始位置
iLeft=Math.round(Math.random()*(width-offWidth));
iTop=10;
objDiv.style.pixelLeft=iLeft;
objDiv.style.pixelTop=iTop;
//定时开始
//startTimer();
}
//主函数，漂浮游动显示广告
this.floatScroll=function(){
var iRnd;
//iRnd=Math.round(Math.random()*100); //此值是为了能使多图显示时产生不同的轨迹
if(objDiv==null)return;
objDiv.style.pixelLeft = iLeft + document.body.scrollLeft;
objDiv.style.pixelTop = iTop + document.body.scrollTop;
if(iRnd>98){leftFlag=!leftFlag;}
//iRnd=Math.round(Math.random()*100);
if(iRnd>99){topFlag=!topFlag;}
if(leftFlag){
iLeft=iLeft+leftStep;
}else{
iLeft=iLeft-leftStep;
}
if(topFlag){
iTop=iTop+topStep;
}else{
iTop=iTop-topStep;
}
if(iLeft<0){
iLeft=0;
leftFlag=true;
}
else if(iLeft>width-offWidth){
iLeft=width-offWidth;
leftFlag=false;
}
if(iTop<0){
iTop=0;
topFlag=true;
}
else if(iTop>height-offHeight){
iTop=height-offHeight;
topFlag=false;
}
}
//定时移动广告的图片
function startTimer(){
if(objName=="")return;
//alert(objName+".floatScroll();");
//inter=setInterval(objName+".floatScroll()",delay);
}
//显示图片的HTML代码
function showImageHtml(adImgSrc,adHref,adTitle){
var sWidth,sHeight;
if(imageWidth<5){
sWidth="";
}else{
sWidth=" width='"+imageWidth+"'";
}
if(imageHeight<5){
sHeight="";
}else{
sHeight=" height='"+imageHeight+"'";
}
document.write("<div id='img"+divID+"' style='position:absolute;'>");
document.write("<a href='"+adHref+"' target='_blank' title='"+adTitle+"'>");
document.write("<img src='"+adImgSrc+"' border='0'"+sWidth+sHeight+">");
document.write("</a></div>");
}
//显示Flash文件的HTML代码
function showFlashHtml(adImgSrc,adHref,adTitle){
var sWidth,sHeight;
if(imageWidth<5){
sWidth=" width='80'";
}else{
sWidth=" width='"+imageWidth+"'";
}
if(imageHeight<5){
sHeight=" height='80'";
}else{
sHeight=" height='"+imageHeight+"'";
}
document.write("<div id='img"+divID+"' style='position:absolute;' onmouseover='clearTimeout(float);' onmouseout='setTimeout(\"setTimer()\",40);'>");
document.write("<a href='"+adHref+"' target='_blank' title='"+adTitle+"'>");
document.write("<object codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0'"+sWidth+sHeight+" align='middle'>");
document.write("<param name='movie' value='"+adImgSrc+"'>");
document.write("<param name='quality' value='high'>");
document.write("<embed src='"+adImgSrc+"'"+sWidth+sHeight+" quality='high' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash'></embed></object>");
document.write("</a></div>");
}
}
