BondelagetMMFolderView = Class.create({
	perPage: null,
	currentPage: null,
	totalRows: null,
	totalPages: null,
	id: null, // the id of the container and the javascript variable

	initialize: function(id, perPage) {
	    this.id = id;
	    this.perPage = perPage;
	    this.currentPage = 0;

	    // determine total count and calculate number of pages
	    this.totalRows = $(this.id).select('li.file').length;
	    this.totalPages = Math.ceil(this.totalRows/this.perPage);

	    this.update();

	    if(this.totalPages > 1) {
		$(this.id).down('div.navigation').removeClassName('hidden');
	    }

	},
	update: function() {
	    var i = 0;
	    var min = this.currentPage*this.perPage;
	    var max = this.perPage*(this.currentPage + 1);
	    $(this.id).select('li.file').each(function(element){
		    if (i >= min && i < max) {
			element.removeClassName('hidden');
		    } else {
			element.addClassName('hidden');
		    }
		    i++;
	    }.bind(this));
	},
	page: function(i) {
	    // flip page by offset i. -1 is backwards
	    if (this.currentPage + i >= 0 && this.currentPage + i < this.totalPages) {
		this.currentPage += i;
		this.update();
	    }
	}
});
