var Pagination = new Class({
	options: {
		currentPage: 0,
		lines: 5
	},
	
	initialize: function(table, options) {
		this.table = table;
		this.setOptions(options);
		
		this._init();
		this._display();
	},
	
	_init: function() {
		this.rows = $ES('tbody tr', this.table);
		this.countPages = Math.ceil(this.rows.length / this.options.lines);
	},
	
	_display: function() {
		this.rows.each(function(row, index) {

			if (index < this.options.lines * this.options.currentPage) {

				row.setStyle('display', 'none');

			} else if (index > this.options.lines * (this.options.currentPage + 1) - 1) {

				row.setStyle('display', 'none');

			} else {

				row.setStyle('display', 'table-row');

			}
		}.bind(this));
	},
	
	goToPage: function(page) {
		if (page < 0 || page > this.countPages - 1) return;
		this.options.currentPage = page;
		this._display();
	},
	
	previousPage: function() {
		this.goToPage(this.options.currentPage - 1);
	},
	
	nextPage: function() {
		this.goToPage(this.options.currentPage + 1);
	},
	
	firstPage: function() {
		this.goToPage(0);
	},
	
	lastPage: function() {
		this.goToPage(this.countPages - 1);
	}
});

Pagination.implement(new Options);