// effect.class
/*
前台显示效果统一调用类
	对联广告,漂浮广告,图片轮换等	
*/
function effect(name,w,h){
	//共有
	this.name			=	name;
	this.width			=	w;
	this.height			=	h;
	//对联
	this.toTop			=	200;
	this.leftContent	=	"";
	this.rightContent	=	"";
	//漂浮
	this.floatImg		=	"";
	this.floatUrl		=	"";
	this.floatObj_x 	=	50;
	this.floatObj_y 	=	60;
	this.sLeft			=	0; 
	this.sTop			=	0; 
	this.xPos			=	0;
	this.yPos			=	0;
	this.step			=	2;
	this.speed			=	20;
	this.TTL			=	"";
	//图片轮换
	this.adNum			=	0;
	this.changeTime		=	3000; //变化间隔时间 默认3000毫秒
	this.picStr			=	"";
	this.linkStr		=	"";
	this.theTimer		=	"";
	this.changePic		=	"";
	this.picArr			=	new Array();
	this.linkArr		=	new Array();
	this.floatObj		=	"";
}
//对联广告
effect.prototype.couplet=function(){
	document.write("<div id='CoupletLeft_"+this.name+"' style='left:0px; top:"+this.toTop+"px;height:"+this.height+"px;position:fixed;width:"+this.width+"px;'>"+this.leftContent+"</div>");
	document.write("<div id='CoupletRight_"+this.name+"' style='right:0px;top:"+this.toTop+"px;height:"+this.height+"px;position:fixed;width:"+this.width+"px;'>"+this.rightContent+"</div>");
	if(navigator.userAgent.indexOf("MSIE")>0) {
		var CL=document.getElementById("CoupletLeft_"+this.name);
		var CR=document.getElementById("CoupletRight_"+this.name);
		CL.style.position="absolute";
		CR.style.position="absolute";
		var top=this.toTop;
		window.onscroll=function(){
			scrollTop = window.pageYOffset || document.documentElement.scrollTop || 0;
			var _top =scrollTop+top;
			CL.style.top=_top;
			CR.style.top=_top;
		}
	}
}

//漂浮广告 在IE6 FF3 测试运行正常 符合w3c transitional.dtd 标准
effect.prototype.floating=function(){
	if(this.floatImg=="")return;
	var floatStr;
	floatStr="<img src='"+this.floatImg+"' border='0'>";	
	if(this.floatUrl!="")floatStr="<a href='"+this.floatUrl+"' target='_blank'>"+floatStr+"</a>";
	document.write("<DIV id=float_"+this.name+" style='position:absolute;z-index:9999'>"+floatStr+"</div>");
	this.floatObj=document.getElementById("float_"+this.name);
	var thisTemp=this;
	this.TTL= setInterval(function(){thisTemp.starFloat()},this.speed);
	this.floatObj.onmouseover=function(){thisTemp.onmouseover();}
	this.floatObj.onmouseout=function(){thisTemp.onmouseout();} 
}
effect.prototype.onmouseover=function(){
	var thisTemp=this;
	clearInterval(thisTemp.TTL);
}
effect.prototype.onmouseout=function(){
	var thisTemp=this;
	this.TTL=setInterval(function(){thisTemp.starFloat()},this.speed)
}
effect.prototype.starFloat=function(){
        this.floatObj_x = this.floatObj.offsetWidth;
        this.floatObj_y = this.floatObj.offsetHeight;
        this.sLeft=Math.max(document.documentElement.scrollLeft,document.body.scrollLeft);
        this.sTop=Math.max(document.documentElement.scrollTop,document.body.scrollTop);
        this.floatObj.style.left = (this.xPos + this.sLeft)+'px';
        this.floatObj.style.top = (this.yPos + this.sTop)+'px';
        if(this.xon) this.xPos += this.step;
        else this.xPos -= this.step;
        if(this.yon) this.yPos += this.step;
        else this.yPos -= this.step;
        if(this.xPos >= (document.documentElement.clientWidth-this.floatObj_x)){
            this.xon = 0;
            this.xPos = document.documentElement.clientWidth-this.floatObj_x;
        }
        if(this.xPos < 0){
            this.xon = 1;
            this.xPos = 0;
        }
        if(this.yPos >= (document.documentElement.clientHeight-this.floatObj_y)){
            this.yon = 0;
            this.yPos = document.documentElement.clientHeight-this.floatObj_y;
        }
        if(this.yPos < 0){
            this.yon = 1;
            this.yPos = 0;
        }
}



//图片轮换 ie6 ff 测试成功
effect.prototype.showImg=function(){
	this.picArr	=this.picStr.split("|");
	this.linkArr=this.linkStr.split("|");
	document.write("<img style='cursor:pointer; filter:revealTrans(duration=2,transition=20)' onclick='jump2url(this.title);' height='"+this.height+"' src='"+this.picArr[0]+"' title='"+this.linkArr[0]+"' width='"+this.width+"' border='0' id='showImg_"+this.name+"'>");
	this.changePic=document.getElementById("showImg_"+this.name);
	this.nextAd();
}
effect.prototype.nextAd=function(){
	if(this.adNum<this.picArr.length-1){
		this.adNum++ ;
	}else{
		this.adNum=0;
	}
	this.setTransition();
	this.changePic.src=this.picArr[this.adNum];
	this.changePic.title=this.linkArr[this.adNum];
	//alert(this.changePic.src);
	this.playTransition();
	var thisTemp=this;
	theTimer=setTimeout(function(){thisTemp.nextAd()},this.changeTime);	
}
effect.prototype.setTransition=function(){
	if (navigator.userAgent.indexOf("MSIE")>0){
		this.changePic.filters.revealTrans.Transition=Math.floor(Math.random()*23);
		this.changePic.filters.revealTrans.apply();
	}	
}
effect.prototype.playTransition=function(){
	if (navigator.userAgent.indexOf("MSIE")>0){
		this.changePic.filters.revealTrans.play();
	}	
}


function jump2url(url){
	jumpTarget='_blank';
	if (url != '' && url!="undefined"){
		window.open(url,jumpTarget);
	}
}
function addFav(sURL,sTitle)
{
if(!sTitle){sTitle=document.title;}
if(!sURL){sURL=document.location.href;}
     try
     {
         window.external.addFavorite(sURL, sTitle);
     }
     catch (e)
     {
         try
         {
             window.sidebar.addPanel(sTitle, sURL, "");
         }
         catch (e)
         {
             alert("加入收藏失败，有劳您手动添加。");
         }
     }
}
function homePage(obj){
	if(document.all){
		obj.style.behavior="url(#default#homepage)";
		obj.setHomePage(siteUrl);
	}
}
