/**
 *  Calculates values for paging-purposes
 *
 */

function Pager(items, currentPage, numPerPage) {

  /**
   *  Count of items
   */
   this.items = 0;

  /**
   *  Current page, starting by 1
   */
   this.currentPage = 0;

  /**
   *  Number of items per page
   */
   this.numPerPage = numPerPage;

  /**
   *  Resulting count of pages
   */
   this.pages = 0;

  /**
   *  Starting index of items, i.e. 0 if currentPage is 1.
   */
  this.currentFromIndex = 0;

  /**
   *  Last index of items
   */
  this.currentToIndex = 0;

  /**
   *  German text for dividing singular / plural of "Eintrag"
   */
  this.title = "";
	/**
	 * Calculates pages, title and indexes.
	 */
	this.calc = function() {
	  	this.pages = Math.ceil(this.items / this.numPerPage);
		if(this.items == 1) {
			this.title = "Eintrag gefunden";
		} else {
			this.title = "Einträge gefunden";
		}
		this.currentFromIndex = (this.currentPage-1)*this.numPerPage;
		this.currentToIndex = Math.min(this.items, this.currentFromIndex + this.numPerPage-1);
	}
  /**
   *  Constructor
   */
  	this.items = items;
  	if(currentPage) this.currentPage = currentPage;
  	else this.currentPage = 1;
  	if(numPerPage) this.numPerPage = numPerPage;
  	else this.numPerPage = 10;
  	this.calc();

}