function selfPager(content, limit) {
	this.page = 1;
	this.limit = limit !== null ? Math.max(1, limit) : 1;
	this.content =  content;
}

selfPager.prototype.getNBResults = function() {
	return this.content.length;
};

selfPager.prototype.setContent = function(content) {
	this.content = content;
}

selfPager.prototype.getContent = function() {
	this.getContent();
}

selfPager.prototype.getResults = function() {
	results = [];
	for (var i = (this.page-1) * this.limit; i < Math.min(this.content.length, (this.page * this.limit)); ++i)
	{
		results.push(this.content[i]);
	}
	return results;
};

selfPager.prototype.getFirstPage = function(){
	return 1;
};

		
selfPager.prototype.getPreviousPage = function(){
	return Math.max(this.getFirstPage(), this.page - 1);
};

selfPager.prototype.getNextPage = function() {
	return Math.min(this.getLastPage(), this.page + 1);
};

selfPager.prototype.getLastPage = function() {
	return Math.ceil(this.content.length/this.limit);
};

selfPager.prototype.getPage = function() {
	return this.page;
};

selfPager.prototype.setPage = function(page) {
	this.page = Math.min(this.getLastPage(), Math.max(this.getFirstPage(), page));
};

selfPager.prototype.getFirstFromPageIndex = function() {
	return (this.page-1) * this.limit;
};

selfPager.prototype.getLastFromPageIndex = function() {
	return (this.page-1) * this.limit + Math.min(this.limit, this.content.length - ((this.page-1) * this.limit)) - 1;
};

