/*!
 * 定时滚动文字插件
 * www.JSPGen.com
 * @revise 1.0
 */
;(function($){$.fn.rollerTimer=function(options){var obj=$(this);if(!obj.length||!options instanceof Object){return options};var settings={list:'',timer:5000,speed:400,showNum:4,rollNum:1,columnWidth:'',rowHeight:'',auto:true,direction:'left',cycle:true,cycleMode:'normal',trigger:'click',hover:true,buttonA:'',buttonB:'',disableClass:'',focus:'',focusOn:'current',focusTrigger:'mouseover',callBack:''};$.extend(settings,options);settings.columnWidth=settings.columnWidth==''?$(settings.list).eq(0).outerWidth(true):settings.columnWidth;settings.rowHeight=settings.rowHeight==''?$(settings.list).eq(0).outerHeight(true):settings.rowHeight;var list=$(settings.list),cycle=settings.cycle,rollNum=settings.rollNum,buttonA=$(settings.buttonA),buttonB=$(settings.buttonB),parElement=list.parent(),elLen=list.length,remainder=elLen-settings.showNum,isLevel=settings.direction=='left'||settings.direction=='right',isFocus=($(settings.focus).length&&rollNum==1&&settings.showNum==1),isCallBack=(settings.callBack&&typeof settings.callBack=='function'),colRow=isLevel?settings.columnWidth:settings.rowHeight,sinRollValue=colRow*rollNum,dir=isLevel?'margin-left':'margin-top',rollTime,rollType,rolled=0,oldIndex=0;if(!list.length){return obj};obj.css(isLevel?'width':'height',(settings.showNum*colRow)+'px').css('overflow','hidden');if(cycle&&(settings.cycleMode==='normal'||remainder<rollNum)){parElement.append(list.clone(true));elLen*=2;};parElement.css(isLevel?'width':'height',(elLen*colRow)+'px');rollNum=rollNum>settings.showNum?settings.showNum:rollNum;var changeBtnClass=((!cycle||cycle&&settings.cycleMode==='back'&&settings.auto)&&settings.disableClass
instanceof Object&&settings.disableClass.leftUp&&settings.disableClass.rightDown&&buttonA.length&&buttonB.length);if(changeBtnClass){buttonA.addClass(settings.disableClass.leftUp);};var leftUp=function(){if(parElement.is(":animated")){return false};var disableScroll=false,num=rollNum,theRest=remainder-rolled;if(cycle&&settings.cycleMode==='normal'){if(rolled==0){parElement.prepend($(settings.list+':gt('+(elLen/2-1)+')')).css(dir,-(elLen/2)*colRow+'px');};}else if(!cycle&&rolled==0){return false;};if((!cycle||(cycle&&settings.cycleMode==='back'))&&rolled<rollNum){num=rolled;disableScroll=true;};rollType=leftUp;var aniConfig={};aniConfig[dir]='+='+num*colRow+'px';parElement.animate(aniConfig,settings.speed,function(){rolled=disableScroll?0:rolled-rollNum;if(cycle){if(settings.cycleMode==='normal'){if(rolled<0){rolled=elLen/2-rollNum};}else if(settings.auto&&settings.cycleMode==='back'){if(rolled==0){clearInterval(rollTime);rollTime=setInterval(rightDown,settings.timer);};};};if(changeBtnClass){toggleClass(rolled)};if(isFocus){curClass(rolled)};if(isCallBack){settings.callBack(rolled,isLevel?'right':'down')};});},rightDown=function(){if(parElement.is(":animated")){return false};var disableScroll=false,num=rollNum,theRest=remainder-rolled;if(!cycle&&theRest==0){return false;};if((!cycle||(cycle&&settings.cycleMode==='back'))&&theRest<rollNum){num=theRest;disableScroll=true;};rollType=rightDown;var aniConfig={};aniConfig[dir]='-='+num*colRow+'px';parElement.animate(aniConfig,settings.speed,function(){rolled=disableScroll?remainder:rolled+rollNum;if(cycle){if(settings.cycleMode==='normal'){if(rolled>=elLen/2){var restRolled=rolled-elLen/2;parElement.append($(settings.list+':lt('+elLen/2+')')).css(dir,(restRolled*colRow)+'px');rolled=restRolled;};if(isFocus&&rolled>remainder){rolled=0};}else if(settings.auto&&settings.cycleMode==='back'){if(rolled==remainder){clearInterval(rollTime);rollTime=setInterval(leftUp,settings.timer);};};};if(changeBtnClass){toggleClass(rolled)};if(isFocus){curClass(rolled)};if(isCallBack){settings.callBack(rolled,isLevel?'left':'up')};});};if(settings.buttonA&&buttonA.length){buttonA[settings.trigger](function(){leftUp();});};if(settings.buttonB&&buttonB.length){buttonB[settings.trigger](function(){rightDown();});};function toggleClass(rolled){if(rolled==0){buttonB.removeClass(settings.disableClass.rightDown);buttonA.addClass(settings.disableClass.leftUp);}else if(rolled==remainder){buttonA.removeClass(settings.disableClass.leftUp);buttonB.addClass(settings.disableClass.rightDown);}else{buttonA.add(buttonB).removeClass(settings.disableClass.leftUp+" "+settings.disableClass.rightDown);};};if(isFocus){var numList=$(settings.focus),curClass=function(index){numList.eq(oldIndex).removeClass(settings.focusOn).end().eq(index).addClass(settings.focusOn);oldIndex=index;};numList.eq(0).addClass(settings.focusOn);numList[settings.focusTrigger](function(){var index=$(this).index(),differ=(oldIndex-index>0);if(index==oldIndex){return false};if(changeBtnClass){toggleClass(index)};var aniConfig={};aniConfig[dir]='-'+index*colRow+'px';curClass(index);parElement.stop().animate(aniConfig,settings.speed,function(){rolled=index;if(isCallBack){settings.callBack(index,isLevel?(differ?'right':'left'):(differ?'down':'up'))};});});};rollType=leftUp;if(settings.auto){if(settings.hover){obj.add(buttonA).add(buttonB).add($(settings.focus)).hover(function(){clearInterval(rollTime);},function(){clearInterval(rollTime);rollTime=setInterval(rollType,settings.timer);});};rollTime=setInterval(settings.direction==='left'||settings.direction==='up'?rightDown:leftUp,settings.timer);};};})(jQuery);