/*!
* jquery cxscroll 1.2.2
* http://code.ciaoca.com/
* https://github.com/ciaoca/cxscroll
* e-mail: ciaoca@gmail.com
* released under the mit license
* date: 2015-09-17
*/
!function(a){"function"==typeof define&&define.amd?define(["jquery"],a):a(jquery)}(function(a){a.cxscroll=function(){var b,c,d,h,i,e={dom:{},api:{},lockstate:!1},f=function(a){return a&&("function"==typeof htmlelement||"object"==typeof htmlelement)&&a instanceof htmlelement?!0:a&&a.nodetype&&1===a.nodetype?!0:!1},g=function(a){return a&&a.length&&("function"==typeof jquery||"object"==typeof jquery)&&a instanceof jquery?!0:!1};for(h=0,i=arguments.length;i>h;h++)g(arguments[h])?b=arguments[h]:f(arguments[h])?b=a(arguments[h]):"function"==typeof arguments[h]?d=arguments[h]:"object"==typeof arguments[h]&&(c=arguments[h]);b.length&&(e.init=function(){var e=this;e.dom.el=b,e.settings=a.extend({},a.cxscroll.defaults,c),e.build(),e.api={play:function(){e.settings.auto=!0,e.play()},stop:function(){e.settings.auto=!1,e.stop()},prev:function(a){a=parseint(a,10),("number"!=typeof a||0>a)&&(a=e.settings.speed),e.goto(e.prevval,a)},next:function(a){a=parseint(a,10),("number"!=typeof a||0>a)&&(a=e.settings.speed),e.goto(e.nextval,a)}},"function"==typeof d&&d(e.api)},e.build=function(){var b=this;if(b.dom.box=b.dom.el.find(".box"),b.dom.list=b.dom.box.find(".list"),b.dom.items=b.dom.list.find("li"),b.itemsum=b.dom.items.length,!(b.itemsum<=1)){if(b.dom.prevbtn=b.dom.el.find(".prev"),b.dom.nextbtn=b.dom.el.find(".next"),b.itemwidth=b.dom.items.outerwidth(),b.itemheight=b.dom.items.outerheight(),"left"===b.settings.direction||"right"===b.settings.direction){if(b.itemwidth*b.itemsum<=b.dom.box.outerwidth())return;b.prevval="left",b.nextval="right",b.moveval=b.itemwidth}else{if(b.itemheight*b.itemsum<=b.dom.box.outerheight())return;b.prevval="top",b.nextval="bottom",b.moveval=b.itemheight}b.dom.list.append(b.dom.list.html()),b.settings.prevbtn&&!b.dom.prevbtn.length&&(b.dom.prevbtn=a("",{"class":"prev"}).prependto(b.dom.el)),b.settings.nextbtn&&!b.dom.nextbtn.length&&(b.dom.nextbtn=a("",{"class":"next"}).prependto(b.dom.el)),b.settings.nextbtn&&b.dom.prevbtn.length&&b.dom.nextbtn.bind("click",function(){b.lockstate||b.goto(b.nextval,b.settings.accel)}),b.settings.prevbtn&&b.dom.prevbtn.length&&b.dom.prevbtn.bind("click",function(){b.lockstate||b.goto(b.prevval,b.settings.accel)}),b.settings.hoverlock&&(b.dom.box.on("mouseenter",function(){b.stop()}),b.dom.box.on("mouseleave",function(){b.play()})),b.play()}},e.play=function(){var a=this;a.settings.auto&&(a.stop(),a.run=settimeout(function(){a.goto()},a.settings.time))},e.stop=function(){"undefined"!=typeof this.run&&cleartimeout(this.run)},e.goto=function(b,c){var e,f,d=this,g=c||d.settings.speed;switch("string"!=typeof b&&(b=d.settings.direction),d.stop(),d.lockstate=!0,b){case"left":case"top":e=0,"left"===b?(0===parseint(d.dom.box.scrollleft(),10)&&d.dom.box.scrollleft(d.itemsum*d.moveval),f=d.dom.box.scrollleft()-d.moveval*d.settings.step,f%d.itemwidth>0&&(f-=f%d.itemwidth-d.itemwidth),e>f&&(f=e),d.dom.box.animate({scrollleft:f},g,d.settings.easing,function(){parseint(d.dom.box.scrollleft(),10)<=e&&d.dom.box.scrollleft(0)})):(0===parseint(d.dom.box.scrolltop(),10)&&d.dom.box.scrolltop(d.itemsum*d.moveval),f=d.dom.box.scrolltop()-d.moveval*d.settings.step,f%d.itemheight>0&&(f-=f%d.itemheight-d.itemheight),e>f&&(f=e),d.dom.box.animate({scrolltop:f},g,d.settings.easing,function(){parseint(d.dom.box.scrolltop(),10)<=e&&d.dom.box.scrolltop(0)}));break;case"right":case"bottom":e=d.itemsum*d.moveval,"right"===b?(f=d.dom.box.scrollleft()+d.moveval*d.settings.step,f%d.itemwidth>0&&(f-=f%d.itemwidth),f>e&&(f=e),d.dom.box.animate({scrollleft:f},g,d.settings.easing,function(){parseint(d.dom.box.scrollleft(),10)>=e&&d.dom.box.scrollleft(0)})):(f=d.dom.box.scrolltop()+d.moveval*d.settings.step,f%d.itemheight>0&&(f-=f%d.itemheight),f>e&&(f=e),d.dom.box.animate({scrolltop:f},g,d.settings.easing,function(){parseint(d.dom.box.scrolltop(),10)>=e&&d.dom.box.scrolltop(0)}));break;default:return}d.dom.box.queue(function(){d.lockstate=!1,d.play(),a(this).dequeue()})},e.init())},a.cxscroll.defaults={direction:"right",easing:"swing",step:1,accel:200,speed:800,time:4e3,auto:!0,hoverlock:!0,prevbtn:!0,nextbtn:!0},a.fn.cxscroll=function(b,c){return this.each(function(){a.cxscroll(this,b,c)}),this}});