/*****	路径：ad.js	********/
/*****	名称：广告类	********/
/*****	作者：应龙	********/
/*****	时间：2008-9-22	********/
/*****	介绍：存放各类广告特效	********/

bit.ad={};

bit.ad.focusAd=function(){};
bit.ad.focusAd.prototype={
	retData:function(maxUrl,minUrl,link){return {'maxUrl':maxUrl,'minUrl':minUrl,'link':link}}
	,base:bit.base,type:{'left':'marginLeft','top':'marginTop'}
	,ulObj:null,width:0,height:0,n:1,speed:1,num:0,nav:null
	,load:function(id,arr,width,height,n,speed,type,nav){
		this.width=width;
		this.height=height;
		this.n=n;
		this.speed=speed;
		this.type=this.type[type];
		this.nav=nav;
		var obj=this.base.$(id),pro=this;
		obj.style.width=width+'px';
		obj.style.height=height+'px';
		obj.innerHTML=this.html(arr,type,nav);
		this.ulObj=this.base.tagArr(obj,'ul');
		if(nav){this.event(this.ulObj[1],type);}
		this.clickLoop=setTimeout(function(){pro.click(pro.num+1,type)},this.speed*1000);
	}
	,html:function(arr,type,nav){
		var len=arr.length,i,str='',strNav='';
		str+='<ul style="width:'+((type=='top')?this.width:this.width*(nav?len:len+1))+'px;height:'+((type=='top')?(this.height*(nav?len:len+1)):this.height)+'px;margin:0px;">';
		strNav+='<div class="navBg" style="height:'+this.height+'px;"></div>';;
		strNav+='<ul class="nav" style="height:'+this.height+'px;">';
		for(i=0;i<len;i++){
			str+='<li style="width:'+this.width+'px;height:'+this.height+'px;background:url('+arr[i].maxUrl+');'+((type=='top')?'':'float:left')+'" onclick="window.open(\''+arr[i].link+'\')"></li>';
			strNav+='<li '+(i==0?'class="on"':'')+'><span style="background:url('+arr[i].minUrl+');"></span><label></label></li>';
		}
		str+=!nav?'<li style="width:'+this.width+'px;height:'+this.height+'px;background:url('+arr[0].maxUrl+');'+((type=='top')?'':'float:left')+'" onclick="window.open(\''+arr[0].link+'\')"></li>':'';
		str+='</ul>';
		strNav+='</ul>';
		str+=nav?strNav:'';
		return str;
	}
	,event:function(ulObj,type){
		var liArr=this.base.tagArr(ulObj,'li'),len=liArr.length,i,pro=this;
		for(i=0;i<len;i++){
			liArr[i].onclick=function(i){
				return function(){pro.click(i,type)};
			}(i);
		}
	}
	,clickLoop:null
	,loop:null
	,on:true
	,click:function(i,type){
		var pro=this;
		clearTimeout(this.loop);
		clearTimeout(this.clickLoop);
		var len=this.base.tagArr(this.ulObj[0],'li').length;
		if(this.nav){
			if(i==len-1){this.on=false;i=len-1;}
			if(i==0){this.on=true;}
			var navLiArr=this.base.tagArr(this.ulObj[1],'li')
			navLiArr[this.num].className='';
			navLiArr[i].className='on';
		}else{
			if(i==len){pro.ulObj[0].style[this.type]='0px';i=1;}
		}
		this.num=i;
		pro.play(pro.ulObj[0],((type=='top')?pro.height*pro.num:pro.width*pro.num),type);
	}
	,play:function(ulObj,width,type){
		var mar=parseInt(ulObj.style[this.type]),pro=this;
		if(-mar==width){
			this.clickLoop=setTimeout(function(){pro.click((pro.on?(pro.num+1):(pro.num-1)),type)},this.speed*1000);
			return;
		}
		var sp=(width-Math.abs(mar))*0.01*this.n;
		sp=(sp>0)?(sp>1?sp:1):(sp<-1?sp:-1);
		ulObj.style[this.type]=mar-sp+'px';		
		this.loop=setTimeout(function(){pro.play(ulObj,width,type);},10);
	}
}
