//动画切换类
function Goog(name,MoveWidth,direction,MoveMode,MovePixel,times){
	var Google={
		box:null,
		index:0,index_o:0,
		fx:function (el,to){
		    //以下无缝滚动用
		    if(this.MoveFX==1){
		        if (this.index_o==0&&this.index==(this.list_l-1))to=(this.list_l-1)*this.MoveWidth;//如果将要移动到复制的最后1个单元
			    if (this.GetObjTopOrLeft(el)==0)this.SetObjTopOrLeft(el,this.list_l*this.MoveWidth);//如果当前位置在原来的首个单元,就切换到复制的首个单元
			}else{
		        if (this.index_o==(this.list_l-1)&&this.index==0)to=this.list_l*this.MoveWidth;//如果将要移动到复制的第1个单元
			    if (this.GetObjTopOrLeft(el)>=this.list_l*this.MoveWidth)this.SetObjTopOrLeft(el,0);//如果当前位置在复制的首个单元,就切换到原来的首个单元
			}

			var getFx=function (a,b,w){//a是当前位置,b是目的地,w:一个单元的宽度,这里的abw不等于下面的abw,这里是死的,下面是实时的
			    switch (MoveMode) {
		        case 1:
				    if(Google.MoveFX==1) return function (){
			            if (a==0)a=(Google.list_l)*w;//如果当前位置在复制的首个单元,就切换到原来的首个单元
					    return [a-=Google.MovePixel,(b-a)>0?(b-Google.list_l*w-a):(b-a)]
					};
					else return function (){
					    if (a>=Google.list_l*w)a=0;//如果当前位置在复制的首个单元,就切换到原来的首个单元
					    return [a+=Google.MovePixel,(a-b)>0?(a-Google.list_l*w-b):(a-b)]
					};
				default :
					var c=Math[(a-b)>0?'floor':'ceil'];
					return function (){return [a+=c((b-a)*0.15),a-b]};//0.15调节动画速度
				}
			};
			var get=getFx(this.GetObjTopOrLeft(el),to,this.MoveWidth);
			clearInterval(el.timer);
			this.showPage();
			el.timer=setInterval(function(){
			    if (Google.Pause==1)return;
				var x=get();
				if (MoveMode==1&&Math.abs(x[1])<=Google.MovePixel){x[0]=to;x[1]=0;}//纠正误差
				Google.SetObjTopOrLeft(el,x[0]);
				if(x[1]==0){clearInterval(el.timer);Google.auto();Google.MovePixel=MovePixel}//说明1个单元已移动到位,继续下一轮循环(定时)
			},10);
		},
		next:function (m){ if (m==1)this.MovePixel=MovePixel*15;this.MoveFX=0;this.nav(1);},
		prev:function (m){ if (m==1)this.MovePixel=MovePixel*15;this.MoveFX=1;this.nav(-1);},
		nav:function (nav){
		    this.stop();
			this.index_o=this.index;//保存上一个index
			this.index+=nav;
			if(this.index<0)this.index=this.list_l-1;
			if(this.index==this.list_l)this.index=0;//通过前两句计算得到当前要进行的index
			this.fx(this.box,this.index*this.MoveWidth);//动画移动一个单元
		},
		GoTo:function (n){//sd add
			this.stop();
			this.MovePixel=MovePixel*15;
			this.index_o=this.index;//保存上一个index
			this.index=n;
			this.fx(this.box,this.index*this.MoveWidth);
		},
		pause:function (m){	this.Pause=m;},
		stop:function (){	clearTimeout(this.autoTimer);},
		auto:function (){
			this.stop();
			if(this.MoveFX==1) this.autoTimer=setInterval(function(){Google.prev()},times);//间隔时间,每隔times秒就执行1次	
			else this.autoTimer=setInterval(function(){Google.next()},times);
		},
		showPage:function (){
			if (this.page) this.page.innerHTML=this.index+1+'/'+this.list_l;
			if (this.PageNum) {
			    this.PageNum.getElementsByTagName("DD")[this.index_o].getElementsByTagName("a")[0].className="";//sd add
			    this.PageNum.getElementsByTagName("DD")[this.index].getElementsByTagName("a")[0].className="hover";//sd add
			}
		},
		SetObjTopOrLeft:function (o,v){
		    (direction=="up")?o.scrollTop=v:o.scrollLeft=v;
		},
		GetObjTopOrLeft:function (o){
			return (direction=="up")?o.scrollTop:o.scrollLeft;
		},
		init:function (box){
		    if (!times) times=5000;
			this.box=document.getElementById(box);
			this.list=this.box.getElementsByTagName("LI");
			this.list_l=this.list.length;
			this.Pause=0;
			if (!MovePixel)MovePixel=2;//MoveMode=1时才有效
			this.MovePixel=MovePixel;
			this.MoveFX=0;//0:正方向移动;1:反方向移动

            var WH=(direction=="up")?this.box.clientHeight:this.box.clientWidth;
			this.MoveWidth=MoveWidth;
			if (!this.MoveWidth) this.MoveWidth=WH//要移动的宽度
			this.box.onmouseover = function(e){//鼠标移进 sd add
				Google.pause(1);
			};
			this.box.onmouseout = function(e){//鼠标移出 sd add
				Google.pause(0);
			};
			try{//创建数字按钮
			    this.PageNum=document.getElementById(box+"_PageNum");
				var ref=this.PageNum.getElementsByTagName("DD")[0];
				for (var i=0;i<this.list_l;++i ) {
					var n=ref.cloneNode(true);
					n.getElementsByTagName("a")[0].innerHTML=(i+1);
					n.getElementsByTagName("a")[0].href="javascript:"+box+".GoTo("+i+")";
					ref.parentNode.appendChild(n);
				};
				ref.parentNode.removeChild(ref);
			}catch(e){};

            /*把所有li再复制多份，无缝滚动用*/
			var t=Math.abs(Math.floor(-((WH-this.MoveWidth)/this.MoveWidth)))+1;//计算1屏显示多少个单元
			var i=0;
            while (this.list_l==this.list.length||this.list.length<t*2){
				if (i>=this.list_l)i=0;
				var n=this.list[i].cloneNode(true);
				this.list[i].parentNode.appendChild(n);
				i+=1;
			}//alert(t+"|"+this.list.length)

			try{this.page=document.getElementById(box+"_page");}catch(e){};
			this.showPage();
			this.auto();
		}
	};
	Google.init(name);
	this.next=function(){Google.next(1)};
	this.prev=function(){Google.prev(1)};
	this.stop=function(){Google.stop()};
	this.auto=function(){Google.auto()};
	this.GoTo=function(n){Google.GoTo(n)};
	this.pause=function(m){Google.pause(m)};
}
