YUI.add("aui-pagination",function(e,t){var n=e.Lang,r=n.isBoolean,i=n.isFunction,s=n.isNumber,o="active",u="boundingBox",a="changeRequest",f="circular",l="click",c="contentBox",h="control",p="disabled",d="formatter",v="hide",m="items",g="li",y="next",b="offset",w="page",E="pagination",S="prev",x="showControls",T="total",N=e.getClassName,C=N(o),k=N(p),L=N(v),A=N(E,h),O=e.Component.create({NAME:E,ATTRS:{circular:{validator:r,value:!0},formatter:{validator:i,valueFn:"_formatterValueFn"},items:{},offset:{setter:"_setInt",value:1},page:{setter:"_setInt",value:0},total:{setter:"_setInt",value:0},showControls:{validator:r,value:!0},strings:{value:{next:"Next",prev:"Prev"}}},HTML_PARSER:{items:function(e){return this._queryItemsIfNotSet(e)},total:function(){return this._countItemsInDoc()}},BIND_UI_ATTRS:[b,x,T],UI_ATTRS:[w],prototype:{CONTENT_TEMPLATE:"<ul></ul>",ITEM_TEMPLATE:'<li class="{cssClass}"><a href="#">{content}</a></li>',TOTAL_CONTROLS:2,items:null,lastState:null,syncUI:function(){var e=this,t=e.get(w);t>0&&e._dispatchRequest({page:t})},bindUI:function(){var e=this,t=e.get(u);e.on("pageChange",e._onPageChange),e.publish(a,{defaultFn:e._defChangeRequest}),t.delegate(l,e._onClickItem,g,e)},renderUI:function(){var e=this;e._renderItemsUI(e.get(T))},getItem:function(e){var t=this;if(s(e)){var n=t.get(m);n&&(e=n.item(e))}return e},getOffsetPageNumber:function(){var e=this;return e.get(b)+e.get(w)},getOffsetTotalPages:function(){var e=this;return e.get(b)+e.get(T)},getTotalItems:function(){var e=this;return e.get(T)+e.TOTAL_CONTROLS},next:function(){var e=this,t=e.get(T);if(t===0)return;var n=e.get(w);return e._dispatchRequest({page:e.get(f)&&n===t?1:Math.min(t,++n)}),e},prev:function(){var e=this,t=e.get(T);if(t===0)return;var n=e.get(w);return e._dispatchRequest({page:e.get(f)&&n===1?t:Math.max(1,--n)}),e},setState:function(e){var t=this;t.set(w,e.page),t.lastState=e},_countItemsInDoc:function(){var e=this,t=e.get("srcNode");return Math.max(0,e._queryItemsIfNotSet(t).size()-e.TOTAL_CONTROLS)},_defChangeRequest:function(e){var t=this;t.setState(e.state)},_dispatchRequest:function(e){var t=this;t.fire(a,{lastState:t.lastState,state:e})},_formatterValueFn:function(){return function(e){var t=this;return n.sub(t.ITEM_TEMPLATE,{content:e,cssClass:""})}},_queryItemsIfNotSet:function(e){var t=this;return t.items||(t.items=e.all(g)),t.items},_onClickItem:function(e){var t=this,n=e.currentTarget;e.preventDefault();if(n.hasClass(k)||n.hasClass(C))return;var r=t.get(m),i=r.indexOf(n),s=r.size()-1;switch(i){case 0:t.prev();break;case s:t.next();break;default:t._dispatchRequest({page:i})}},_onPageChange:function(e){var t=this;if(e.prevVal!==e.newVal){var n=t.getItem(e.prevVal);n&&n.removeClass(C)}},_renderItemsUI:function(t){var r=this,i=r.ITEM_TEMPLATE,s=r.get(d),o=r.get(b),u,a="";a+=n.sub(i,{content:r.getString(S),cssClass:A});for(u=o;u<=o+t-1;u++)a+=s.apply(r,[u]);a+=n.sub(i,{content:r.getString(y),cssClass:A});var f=e.NodeList.create(a);r.set(m,f),r.get(c).setContent(f),r.get(x)||(f.first().remove(),f.last().remove())},_setInt:function(e){return n.toInt(e)},_syncNavigationUI:function(){var e=this,t=e.get(m);t.first().toggleClass(k,e.get(w)===1),t.last().toggleClass(k,e.get(w)===e.get(T))},_uiSetOffset:function(e){var t=this;t._renderItemsUI(t.get(T))},_uiSetPage:function(e){var t=this;t.get(f)||t._syncNavigationUI();if(e===0||e===t.getTotalItems())return;var n=t.getItem(e);n&&n.addClass(C)},_uiSetShowControls:function(e){var t=this;t._renderItemsUI(t.get(T))},_uiSetTotal:function(e){var t=this;t._renderItemsUI(e)}}});e.Pagination=O},"2.0.0",{requires:["node-event-delegate","aui-node","aui-component","widget-htmlparser"]});
