var Pager=new Class(
	{
		Implements: [ Options ],

		options: {
			container: false,
			total: 0,
			totalall: 0,
			layout: 10,
			current: 1,
			reverse: false,
			baseUrl: '#',
			next: 'next'
		},

		initialize: function( options )
		{
			this.setOptions( options );

			this.options.container = $( this.options.container );

			if( this.options.container )
			{
				var _this = this;
				this.pages = this.options.container.getElement( '.pages' );
				this.slider = this.options.container.getElement( '.slider' );
				this.knob = this.options.container.getElement( '.knob' );

				if( this.options.total<=this.options.layout )
				{
					this.options.layout = this.options.total;
					this.slider.setStyle( 'display','none' );
				}
				if( this.options.current>this.options.total && this.options.current != this.options.totalall  )
				{
					this.options.current = this.options.total;
				} else if(this.options.current == this.options.totalall) {
					this.options.current = this.options.totalall;
				}

				new Slider(
					this.options.container.getElement( '.slider' ),
					this.knob,
					{
						range: [ 1,this.options.total-this.options.layout+1 ],
						snap: false,
						onChange: function( value )
						{
							var html = '<ul><li class="first"><strong>Страницы:</strong></li>';

							for( var i=0,l=_this.options.layout;i<l;i++ )
							{
								var j = _this.options.reverse ? _this.options.total-value-i+1 : value+i;
								var url = _this.options.baseUrl.replace( /<([a-z]*):page_id>/i,( ( j-1 )>0 ? "$1" + j : '' ) );
								html+= '<li' + (_this.options.current==j ? ' class="active"' : '') + '><a href="' + url + '">' + j + '<\/a><\/li>';
								if(i == (l - 1)) {
									var url = _this.options.baseUrl.replace( /<([a-z]*):page_id>/i,( ( j-1 )>0 ? "$1" + 'all' : '' ) );
									html+= '<li' + (_this.options.current==_this.options.totalall ? ' class="active"' : '') + '><a href="' + url + '"><strong>все</strong><\/a><\/li>';
								}
							}
							html+= '<\/ul>';
							_this.pages.set( 'html',html );
						}
					}
				).set(
					this.options.reverse
						?
							Math.floor( this.options.total-this.options.current-this.options.layout/2+2 )
						:
							Math.floor( this.options.current-this.options.layout/2+1 )
				);
			}
		}
	}
);
