(function($){
if(!$.registerNameSpace("ydapp.autoSlideClass")){return false;}
/**
* @desc 内容轮播滚动类
* @调用方法
(new $.ydapp.autoSlideClass.Class({
	"id_class":".conCase",
	"listArr":conListArr,
	"indexImg":imgIndex,
	"leftBar":".leftBar",
	"rightBar":".rightBar",
	"position":"left-right",
	"autoPlay":true,
	"step":51,
	"time":0,
	"moveDomNumber":3,
	"pauseTime":6000
})).Start();

var options={
	id_class:"列表容器#id或者.class",
	listArr:[<li></li>],
	indexImg:0,
	leftBar:obj,
	rigthBar:obj,
	numBar:obj,
	 position:"移动方向",
	autoPlay:true,
	step:"一次移动距离",
	time:"执行移动步长间隔时间",
	pauseTime:"暂停移动间隔时间",
	moveDomNumber:"一次移动多少个list dom",
	callback:function(){}
}
*/
$.registerNameSpace("ydapp.autoSlideClass");
/**************************************************************************************/
/*视频首页、小游戏-全部专题 滚动方法*/
$.ydapp.autoSlideClass.videoIndexSlides=function(sildeCaseId, leftBarId, rightBarId, numBarId){
	var showlen=1;
	var conListArr=[];
	var numBarArr=[];
	$(sildeCaseId).children().children().each(function(i){
		conListArr.push($(this).get(0).outerHTML);			
		if(i==0){
			numBarArr.push('<a class="active" href="javascript:;" index="'+i+'">'+parseInt(i+1)+'</a>');
		}else{
			$(this).remove();
			numBarArr.push('<a href="javascript:;" index="'+i+'">'+parseInt(i+1)+'</a>');
		}
	});
	if(conListArr.length<=1){
		var leftBarClass=$(leftBarId).attr("class");
		var rigthBarClass=$(rightBarId).attr("class");
		$(leftBarId).removeClass().addClass(leftBarClass+"_none").focus(function(){this.blur();});
		$(rightBarId).removeClass().addClass(rigthBarClass+"_none").focus(function(){this.blur();});
		return;
	}
	if(numBarId){
		$(numBarId).html(numBarArr.join(""));
	}
	//$(sildeCaseId).empty().html(conListArr[0]);
	(new this.Class({
		"position":"left-right",
		"easing":"easeInQuad",
		"id_class":sildeCaseId,
		"listArr":conListArr,
		"leftBar":leftBarId,
		"rightBar":rightBarId,
		"numBar":numBarId,
		"numBarEventName":"mousemove",
		"autoPlay":false,
		"time":500,
		"moveDomNumber":1,
		"pauseTime":6000
	})).Start();
};
/**************************************************************************************/
/*详情页截图轮播*/
$.ydapp.autoSlideClass.content_imgSlide=function(sildeCaseId, leftBarId, rightBarId,numBarId){
	var conListArr=[];
	var numBarArr=[];
	$(sildeCaseId+" li").each(function(i){
		var imgObj=$(this).find("img");
		(new Image()).src=imgObj.attr("src");
		$(this).css({background:"url("+imgObj.attr("src")+") no-repeat center center"});
		imgObj.remove();
		conListArr.push($(this).get(0).outerHTML);
		if(i==0){
			numBarArr.push('<a class="active" href="javascript:;" index="'+i+'">'+i+'</a>');
		}else{
			numBarArr.push('<a href="javascript:;" index="'+i+'">'+i+'</a>');
		}
	});
	if(numBarId){
		$(numBarId).html(numBarArr.join(""));
	}
	if(conListArr.length<=1){
		$(numBarId).hide();
		var leftBarClass=$(leftBarId).attr("class");
		var rigthBarClass=$(rightBarId).attr("class");
		$(leftBarId).removeClass().addClass(leftBarClass+"_none").focus(function(){this.blur();});
		$(rightBarId).removeClass().addClass(rigthBarClass+"_none").focus(function(){this.blur();});
		return;
	}
	$(sildeCaseId+" > ul").empty().html(conListArr[0]);
	(new this.Class({
		"position":"left-right",
		"easing":"easeInOutCirc",
		"id_class":sildeCaseId,
		"listArr":conListArr,
		"leftBar":leftBarId,
		"rightBar":rightBarId,
		"numBar":numBarId,
		"numBarEventName":"mousemove",
		"autoPlay":true,
		"time":500,
		"moveDomNumber":1,
		"pauseTime":6000
	})).Start();
};
/**************************************************************************************/
/*图片轮播方法*/
$.ydapp.autoSlideClass.imgSlide=function(sildeCaseId, leftBarId, rightBarId,numBarId,slideTextId,callback,time){
	var conListArr=[];
	var numBarArr=[];
	var conTextArr=[];
	$(sildeCaseId+" li").each(function(i){
		conListArr.push($(this).get(0).outerHTML);
		if(slideTextId){
			conTextArr.push($(slideTextId).find("li").get(i).outerHTML);
		}
		if(i==0){
			numBarArr.push('<a class="active" href="javascript:;" index="'+i+'">'+i+'</a>');
		}else{
			numBarArr.push('<a href="javascript:;" index="'+i+'">'+i+'</a>');
		}
		(new Image()).src=$(this).find("img").attr("src");
	});
	if(numBarId){
		$(numBarId).html(numBarArr.join(""));
	}
	if(slideTextId){
		$(slideTextId).empty().html(conTextArr[0]);
	}
	if(conListArr.length<=1){
		$(leftBarId).remove();
		$(rightBarId).remove();
		return;
	}
	$(sildeCaseId+" > ul").empty().html(conListArr[0]).parent().parent().hover(function(){
		$(leftBarId+","+rightBarId).show();
	},function(){
		$(leftBarId+","+rightBarId).hide();
	});
	(new this.Class({
		"position":"left-right",
		"easing":"easeInOutCirc",
		"id_class":sildeCaseId,
		"listArr":conListArr,
		"leftBar":leftBarId,
		"rightBar":rightBarId,
		"numBar":numBarId,
		"conText":slideTextId,
		"conTextArr":conTextArr,
		"numBarEventName":"mousemove",
		"autoPlay":true,
		"time":time||400,
		"moveDomNumber":1,
		"pauseTime":3000,
		"callback":callback
	})).Start();
};
/*回调滚动图片说明文本方法*/
$.ydapp.autoSlideClass.imgSlide.scrollText=function(){
	if(typeof arguments[0] =="undefined"){return false;}
	var that=arguments[0];
	var conText= that.conText;
	if(that.domAppendWhere=="prepend"){
		conText.prepend(that.conTextArr[that.backcallIndexImg[0]]);
		conText.scrollTop(conText.height());
		move(-1);
	}else{
		conText.append(that.conTextArr[that.backcallIndexImg[0]]);
		move(1);
	}
	function move(n){
		var _h=(n<0)?0:conText.height();
		conText.animate({scrollTop: _h},that.animateTime,that.easing,function(){
			if(n<0){
				conText.find("li").last().remove();
			}else{
				conText.find("li").first().remove();
				conText.scrollTop(0);
			}
		});
	}
}
/**************************************************************************************/
/*内容滚动方法*/
$.ydapp.autoSlideClass.type0=function(sildeCaseId, leftBarId, rightBarId, showlen,autoPlay,time,pauseTime){
	showlen=showlen||1;//默认显示数量
	var conListArr=[];
	$(sildeCaseId+" li").each(function(){
		conListArr.push($(this).get(0).outerHTML);			 
	});
	if(conListArr.length<=showlen){
		var leftBarClass=$(leftBarId).attr("class");
		var rigthBarClass=$(rightBarId).attr("class");
		$(leftBarId).removeClass().addClass(leftBarClass+"_none").focus(function(){this.blur();});
		$(rightBarId).removeClass().addClass(rigthBarClass+"_none").focus(function(){this.blur();});
		return;
	}
	var imgIndex=0;
	var tmpHtml=conListArr.slice(imgIndex);
	if(tmpHtml.length<showlen){
		tmpHtml=tmpHtml.concat(conListArr.slice(0,showlen-tmpHtml.length));
	}else{
		tmpHtml=tmpHtml.slice(0,showlen);
	}
	$(sildeCaseId+" > ul").empty().html(tmpHtml.join(""));
	(new this.Class({
		"position":"left-right",
		"easing":"easeInOutCirc",
		"id_class":sildeCaseId,
		"listArr":conListArr,
		"leftBar":leftBarId,
		"rightBar":rightBarId,
		"autoPlay":autoPlay,
		"time":time||500,
		"moveDomNumber":showlen,
		"pauseTime":pauseTime||6000
	})).Start();
};
/**************************************************************************************/
/*滚动类*/
$.ydapp.autoSlideClass.Class=function(options){
	options=options||{};
	this.Timer = [null,null];
	this.id_class=options.id_class||null;
	this.leftBar=($(options.leftBar).length>0)?$(options.leftBar):null;
	this.rightBar=($(options.rightBar).length>0)?$(options.rightBar):null;
	this.numBar=($(options.numBar).length>0)?$(options.numBar):null;
	this.numBarEventName=options.numBarEventName||"mouseover";
	this.conText=($(options.conText).length>0)?$(options.conText):null;
	this.conTextArr=options.conTextArr||[];
	this.position=options.position||"left-right";
	this.easing=options.easing||"easeOutQuad";//缓动方法 使用easing插件
	this.animateTime=options.time||0;//动画持续时间
	this.autoPlay=options.autoPlay||false;
	this.domAppendWhere="append";
	this.pauseTime=options.pauseTime||6000;
	this.indexImg=options.indexImg||0;
	this.moveDomNumber=options.moveDomNumber||1;
	this.fn=options.callback||function(){};
	this.barClickPlay=this.autoPlay||false;//未设置自动播放，控制bar事件启动自动播放
	this.conCase=$(this.id_class);
	this.conCaseWidth=this.conCase.innerWidth()||620;
	this.conCaseHeight=this.conCase.innerHeight()||200;
	this.ulObj=this.conCase.children();
	this.conLiWidth=this.ulObj.children().innerWidth()||120;
	this.conLiHeight=this.ulObj.children().innerHeight()||180;
	this.listArr=options.listArr||[];
	this.isMoving=false;
	this.Start=function(){
		if(this.position=="left-right"){
			this.ulObj.width(this.conCaseWidth*this.moveDomNumber*2.5);//初始化UL宽度
		}else{
			this.ulObj.width("105%");
			this.ulObj.height(this.conCaseHeight*this.moveDomNumber*2.5);//初始化UL高度
		}
		var that=this;
		
		if(this.leftBar){
			this.leftBar.focus(function(){$(this).blur()}).click(function(){
				if(that.isMoving){return false;}
				that.reWriteList(that.addDomList("prepend"));
			}).hover(function(){that.autoPlay=false;that.Stop();},function(){that.reStart();});
		}
		
		if(this.rightBar){
			this.rightBar.focus(function(){$(this).blur()}).click(function(){
				if(that.isMoving){return false;}
				that.reWriteList(that.addDomList("append"));
			}).hover(function(){that.autoPlay=false;that.Stop();},function(){that.reStart();});
		}
		
		if(this.numBar){
			var clickTimer=100;
			if(this.numBarEventName=="click"){
				this.numBar.find("a").bind("mousemove",function(){
					clickTimer=0;
					that.autoPlay=false;
					that.Stop();								   
				});
			}
			this.numBar.find("a").unbind().focus(function(){$(this).blur()}).bind(this.numBarEventName,function(){
				that.autoPlay=false;
				that.Stop();
				if(that.isMoving){return;}
				var index=parseInt($(this).attr("index"));
				clearTimeout(that.Timer[1]);
				that.Timer[1]=setTimeout(function(){
					if(that.indexImg==index){
						return;
					}else if(that.indexImg>index){
						that.indexImg=index+1;
						that.reWriteList(that.addDomList("prepend"));
					}else{
						that.indexImg=index-1;
						that.reWriteList(that.addDomList("append"));
					}
					that.numBar.find("a").removeClass("active").eq(index).addClass("active");
				 },clickTimer);
				return false;
			}).bind("mouseout",function(){
				clearTimeout(that.Timer[1]);
				that.reStart();
			});
		}
		
		if(this.conText){
			this.conText.hover(function(){that.autoPlay=false;that.Stop();},function(){that.reStart();});
		}
		this.conCase.hover(function(){that.autoPlay=false;that.Stop();},function(){that.reStart();});
		if(this.autoPlay){
			this.reStart();
		}
	};
	this.addDomList=function(where){
		this.domAppendWhere=where;
		var listLen=this.listArr.length;
		switch(where){
			case "prepend":
				var indexArr=[this.indexImg];
				for(var i=0;i<this.moveDomNumber;i++){
					indexArr.push((indexArr[i]-1<0)?listLen-1:indexArr[i]-1);
				}
				indexArr.shift();
				if(this.indexImg==indexArr[indexArr.length-1]){return [];}
				this.indexImg=indexArr[indexArr.length-1];
				break;
			default:
				var index=this.indexImg;
				for(var i=0;i<this.moveDomNumber-1;i++){
					index=(index+1>=listLen)?0:index+1;
				}
				var indexArr=[index];
				for(var i=0;i<this.moveDomNumber;i++){
					indexArr.push((indexArr[i]+1>=listLen)?0:indexArr[i]+1);
				}
				indexArr.shift();
				if(this.indexImg==indexArr[0]){return [];}
				this.indexImg=indexArr[0];
				break;
		}
		return indexArr;
	},
	this.reWriteList=function(indexArr){
		this.backcallIndexImg=indexArr;//此属性回调函数中使用
		if(indexArr.length<1){return;}
		for(var i=0,l=indexArr.length;i<l;i++){
			if(this.domAppendWhere=="prepend"){
				this.ulObj.prepend(this.listArr[indexArr[i]]);
				if(this.position=="left-right"){
					this.conCase.scrollLeft(this.conLiWidth*(i+1));
				}else{
					this.conCase.scrollTop(this.conLiHeight);
				}
				if(i>=l-1){
					this.Move(-1);
				}
			}else{
				this.ulObj.append(this.listArr[indexArr[i]]);
				if(i>=l-1){
					this.Move(1);
				}
			}
		}
		if(this.numBar){
			this.numBar.find("a").removeClass("active").eq(indexArr[0]).addClass("active");
		}
		this.fn(this);
	};
	this.Move=function(n){
		this.Stop();
		this.isMoving=true;
		var that=this;
		switch(this.position){
			case "left-right":
				var _w=(n<0)?0:this.conLiWidth*this.moveDomNumber;
				this.conCase.animate({scrollLeft: _w},this.animateTime,this.easing,function(){
					that.isMoving=false;
					if(n<0){
						for(var i=0;i<that.moveDomNumber;i++){
							that.ulObj.children().last().remove();
						}
					}else{
						for(var i=0;i<that.moveDomNumber;i++){
							that.ulObj.children().first().remove();
						}
						that.conCase.scrollLeft(0);
					}
					if(that.autoPlay){that.reStart();}
					return;								   
				});
				break;
			default:
				var _h=(n<0)?0:this.conLiHeight*this.moveDomNumber;
				this.conCase.animate({scrollTop: _h},this.animateTime,this.easing,function(){
					that.isMoving=false;
					if(n<0){
						for(var i=0;i<that.moveDomNumber;i++){
							this.ulObj.children().last().remove();
						}
					}else{
						for(var i=0;i<that.moveDomNumber;i++){
							that.ulObj.children().first().remove();
						}
						that.conCase.scrollTop(0);
					}
					if(that.autoPlay){that.reStart();}
					return;															   
				});
				break;
		}
	};
	this.Stop=function(){
		clearTimeout(this.Timer[0]);
	};
	this.reStart=function(){
		this.Stop();
		this.autoPlay=true;
		var that=this;
		if(this.autoPlay && this.barClickPlay){
			this.Timer[0]=setTimeout(function(){that.reWriteList(that.addDomList(that.domAppendWhere));},this.pauseTime);
		}
	}
}

})(jQuery);
/**************************************************************************************/
/*easing插件*/
jQuery.easing.jswing=jQuery.easing.swing;jQuery.extend(jQuery.easing,{def:"easeOutQuad",swing:function(e,f,a,h,g){return jQuery.easing[jQuery.easing.def](e,f,a,h,g)},easeInQuad:function(e,f,a,h,g){return h*(f/=g)*f+a},easeOutQuad:function(e,f,a,h,g){return -h*(f/=g)*(f-2)+a},easeInOutQuad:function(e,f,a,h,g){if((f/=g/2)<1){return h/2*f*f+a}return -h/2*((--f)*(f-2)-1)+a},easeInCubic:function(e,f,a,h,g){return h*(f/=g)*f*f+a},easeOutCubic:function(e,f,a,h,g){return h*((f=f/g-1)*f*f+1)+a},easeInOutCubic:function(e,f,a,h,g){if((f/=g/2)<1){return h/2*f*f*f+a}return h/2*((f-=2)*f*f+2)+a},easeInQuart:function(e,f,a,h,g){return h*(f/=g)*f*f*f+a},easeOutQuart:function(e,f,a,h,g){return -h*((f=f/g-1)*f*f*f-1)+a},easeInOutQuart:function(e,f,a,h,g){if((f/=g/2)<1){return h/2*f*f*f*f+a}return -h/2*((f-=2)*f*f*f-2)+a},easeInQuint:function(e,f,a,h,g){return h*(f/=g)*f*f*f*f+a},easeOutQuint:function(e,f,a,h,g){return h*((f=f/g-1)*f*f*f*f+1)+a},easeInOutQuint:function(e,f,a,h,g){if((f/=g/2)<1){return h/2*f*f*f*f*f+a}return h/2*((f-=2)*f*f*f*f+2)+a},easeInSine:function(e,f,a,h,g){return -h*Math.cos(f/g*(Math.PI/2))+h+a},easeOutSine:function(e,f,a,h,g){return h*Math.sin(f/g*(Math.PI/2))+a},easeInOutSine:function(e,f,a,h,g){return -h/2*(Math.cos(Math.PI*f/g)-1)+a},easeInExpo:function(e,f,a,h,g){return(f==0)?a:h*Math.pow(2,10*(f/g-1))+a},easeOutExpo:function(e,f,a,h,g){return(f==g)?a+h:h*(-Math.pow(2,-10*f/g)+1)+a},easeInOutExpo:function(e,f,a,h,g){if(f==0){return a}if(f==g){return a+h}if((f/=g/2)<1){return h/2*Math.pow(2,10*(f-1))+a}return h/2*(-Math.pow(2,-10*--f)+2)+a},easeInCirc:function(e,f,a,h,g){return -h*(Math.sqrt(1-(f/=g)*f)-1)+a},easeOutCirc:function(e,f,a,h,g){return h*Math.sqrt(1-(f=f/g-1)*f)+a},easeInOutCirc:function(e,f,a,h,g){if((f/=g/2)<1){return -h/2*(Math.sqrt(1-f*f)-1)+a}return h/2*(Math.sqrt(1-(f-=2)*f)+1)+a},easeInElastic:function(f,h,e,l,k){var i=1.70158;var j=0;var g=l;if(h==0){return e}if((h/=k)==1){return e+l}if(!j){j=k*0.3}if(g<Math.abs(l)){g=l;var i=j/4}else{var i=j/(2*Math.PI)*Math.asin(l/g)}return -(g*Math.pow(2,10*(h-=1))*Math.sin((h*k-i)*(2*Math.PI)/j))+e},easeOutElastic:function(f,h,e,l,k){var i=1.70158;var j=0;var g=l;if(h==0){return e}if((h/=k)==1){return e+l}if(!j){j=k*0.3}if(g<Math.abs(l)){g=l;var i=j/4}else{var i=j/(2*Math.PI)*Math.asin(l/g)}return g*Math.pow(2,-10*h)*Math.sin((h*k-i)*(2*Math.PI)/j)+l+e},easeInOutElastic:function(f,h,e,l,k){var i=1.70158;var j=0;var g=l;if(h==0){return e}if((h/=k/2)==2){return e+l}if(!j){j=k*(0.3*1.5)}if(g<Math.abs(l)){g=l;var i=j/4}else{var i=j/(2*Math.PI)*Math.asin(l/g)}if(h<1){return -0.5*(g*Math.pow(2,10*(h-=1))*Math.sin((h*k-i)*(2*Math.PI)/j))+e}return g*Math.pow(2,-10*(h-=1))*Math.sin((h*k-i)*(2*Math.PI)/j)*0.5+l+e},easeInBack:function(e,f,a,i,h,g){if(g==undefined){g=1.70158}return i*(f/=h)*f*((g+1)*f-g)+a},easeOutBack:function(e,f,a,i,h,g){if(g==undefined){g=1.70158}return i*((f=f/h-1)*f*((g+1)*f+g)+1)+a},easeInOutBack:function(e,f,a,i,h,g){if(g==undefined){g=1.70158}if((f/=h/2)<1){return i/2*(f*f*(((g*=(1.525))+1)*f-g))+a}return i/2*((f-=2)*f*(((g*=(1.525))+1)*f+g)+2)+a},easeInBounce:function(e,f,a,h,g){return h-jQuery.easing.easeOutBounce(e,g-f,0,h,g)+a},easeOutBounce:function(e,f,a,h,g){if((f/=g)<(1/2.75)){return h*(7.5625*f*f)+a}else{if(f<(2/2.75)){return h*(7.5625*(f-=(1.5/2.75))*f+0.75)+a}else{if(f<(2.5/2.75)){return h*(7.5625*(f-=(2.25/2.75))*f+0.9375)+a}else{return h*(7.5625*(f-=(2.625/2.75))*f+0.984375)+a}}}},easeInOutBounce:function(e,f,a,h,g){if(f<g/2){return jQuery.easing.easeInBounce(e,f*2,0,h,g)*0.5+a}return jQuery.easing.easeOutBounce(e,f*2-g,0,h,g)*0.5+h*0.5+a}});


