ScalingPaginator=new JS.Class('ScalingPaginator',{include:[JS.State,Ojay.Observable],initialize:function(b,a){this._6=b;a=this._4=a||{};a.perPage=a.perPage||this.klass.PER_PAGE;a.scrollTime=a.scrollTime||this.klass.SCROLL_TIME;a.pushFade=a.pushFade||this.klass.PUSH_FADE_TIME;a.pushSlide=a.pushSlide||this.klass.PUSH_SLIDE_TIME;a.direction=a.direction||this.klass.DIRECTION;a.easing=a.easing||this.klass.EASING;this.setState('CREATED')},hasLeft:function(){if(this.position.align==='left'){return this.position.index>0}else{return this.getLeftPages().length>0}},hasRight:function(){if(this.position.align==='right'){return this.position.index<this._0.length-1}else{return this.getRightPages().length>0}},getLeftPages:function(){var a=this.position.align==='left',d=this.position.index,c,e;if(!a)d+=1;c=this._0.slice(0,d).reverse();e=this.makePages(c).reverse();if(!a)e.pop();return e.map(function(b){return b.reverse()})},getRightPages:function(){var b=this._0.slice(this.position.index),a=this.makePages(b);if(this.position.align!=='right')a.shift();return a},makePages:function(c){var e=this.getViewportWidth(),f=0;return(c||[]).reduce(function(b,a){var d=a.getWidth();f+=d;if(f>e){f=d;b.push([a])}else{b[b.length-1].push(a)}return b},[[]])},getOffset:function(d){var c=d.index,e=d.align==='left'?[0,c]:[c+1];return[].slice.apply(this._0,e).reduce(function(b,a){return b-a.getWidth()},0)},states:{READY:{previous:function(){var b=this.getLeftPages(),a,d,c;if(b.length<1)return;if(b.length===1){a='left';c=0}else{d=b[b.length-1];a=this.position.align;c=this.position.index-d.length}this.setPosition({align:a,index:c})},next:function(){var b=this.getRightPages(),a,d,c;if(b.length<1)return;if(b.length===1){a='right';c=this._0.length-1}else{d=b[0];a=this.position.align;c=this.position.index+d.length}this.setPosition({align:a,index:c})},setPosition:function(b){var a=this.position.align,d=this.position.index,c=b.align,e=b.index,f={},g,h;if(c===a&&e===d)return;if(e<0||e>=this._0.length)return;if(c!==a){g={};h=this.getWidth()-this.getViewportWidth()+this.getOffset(this.position);g[a]='';g[c]=-h+'px';this._1.setStyle(g)}f[c]={to:this.getOffset(b)};this.setState('SCROLLING');return this._1.animate(f,this._4.scrollTime)._(function(){this.position=b;this.setState('READY');if(typeof callback==='function'){callback.call(scope||null,this,this.position)}this.notifyObservers('positionChange',this.position);if(a!==c){this.notifyObservers('directionChange',c)}}.bind(this))},addControls:function(b){var a=new(b||this.klass.Controls)(this);this._2.insert(a.getHTML(),'after');return a}},SCROLLING:{},CREATED:{setup:function(){this._1=Ojay(this._6);this._0=this._1.children().map(Ojay);this.position={align:'left',index:0};var b=this.getRegion(),a=b.width,d=b.pageHeight;this._9=b.pageWidth*this._4.perPage;this._2=Ojay(Ojay.HTML.div({className:'paginator horizontal'}));this._2.setStyle({overflow:'hidden',position:'relative',height:d+'px',margin:0,border:'none',padding:0});this._1.setStyle({position:'absolute',width:a+'px',height:d+'px'});this._1.insert(this._2,'before');this._2.insert(this._1);Ojay(window).on('resize',this._a,this);this.setState('READY')},getHTML:function(){return this.setup()}}},getHTML:function(){return this._2},getRegion:function(){return this._0.reduce(function(b,a){a=Ojay(a);var d=a.getWidth(),c=a.getHeight();b.width+=d;if(d>b.pageWidth){b.pageWidth=d}if(c>b.pageHeight){b.pageHeight=c}return b},{width:0,pageHeight:0,pageWidth:0})},getWidth:function(){return this.getRegion().width},getHeight:function(){return this.getRegion().height},getViewportWidth:function(){return this._2.getWidth()},extend:{PER_PAGE:5,SCROLL_TIME:0.5,PUSH_FADE_TIME:0.3,PUSH_SLIDE_TIME:0.3,DIRECTION:'horizontal',EASING:'default',Controls:new JS.Class('ScalingPaginator.Controls',{initialize:function(b){this.paginator=b},previous:function(){this.paginator.previous()},next:function(){this.paginator.next()},getHTML:function(){if(this._5)return this._5;var a,d,c;a=Ojay(Ojay.HTML.div({className:'paginator-controls horizontal'},function(b){d=Ojay(b.div({className:'previous'},'Previous'));c=Ojay(b.div({className:'next'},'Next'))}));[d,c].forEach(function(b){b.on('mouseover').addClass('hovered');b.on('mouseout').removeClass('hovered')});d.on('click',this.previous,this);c.on('click',this.next,this);this.paginator.on('positionChange',this._3,this);Ojay(window).on('resize',this._3,this);this._7=d;this._8=c;this._3();return this._5=a},_3:function(){this._7[this.paginator.hasLeft()?'removeClass':'addClass']('disabled');this._8[this.paginator.hasRight()?'removeClass':'addClass']('disabled')}})}});
