var Pagination = new Class({
	options: {
		currentPage: 0,
		lines: 5
	},
	
	initialize: function(table, Prev, Next, content, options) {
		this.table = table;
		this.PrevButton = $(Prev);
		this.NextButton = $(Next);
		this.content = content;
		this.setOptions(options);		
		this._init();
		this._display();
		this._initButtons();
	},
	
	_init: function() {
		this.rows = this.content;
		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');
				row.setStyle('opacity', 0);
			} else if (index > this.options.lines * (this.options.currentPage + 1) - 1) {
				row.setStyle('display', 'none');
				row.setStyle('opacity', 0);
			} else {
				row.setStyle('display', 'block');
				row.fade(1);				
			}
		}.bind(this));
		if (this.options.currentPage == 0) this.PrevButton.addClass('disable');
		else this.PrevButton.removeClass('disable');		
		if (this.options.currentPage == this.countPages - 1) this.NextButton.addClass('disable');
		else this.NextButton.removeClass('disable');
	},
	
	goToPage: function(el,page) {
		if (page < 0 || page > this.countPages - 1)	return;
			this.options.currentPage = page;
			this._display();
			//el.fade(1);
		
	},
	
	previousPage: function(el) {
		this.goToPage(el,this.options.currentPage - 1);
	},
	
	nextPage: function(el) {
		this.goToPage(el,this.options.currentPage + 1);
	},
	
	firstPage: function(el) {
		this.goToPage(el,0);
	},
	
	lastPage: function(el) {
		this.goToPage(el,this.countPages - 1);
	},
	_initButtons: function(){
		this.PrevButton.addEvent('click', function(e) {
			new Event(e).stop();
			this.previousPage(this.PrevButton);
		}.bind(this));				
		this.NextButton.addEvent('click', function(e) {
			new Event(e).stop();
			this.nextPage(this.NextButton);
		}.bind(this));		
	}
	
	
});

Pagination.implement(new Options);