// This is a very simple demo that shows how a range of elements can
// be paginated.

/**
 * Callback function that displays the content.
 *
 * Gets called every time the user clicks on a pagination link.
 *
 * @param {int}page_index New Page index
 * @param {jQuery} jq the container with the pagination links as a jQuery object
 */
function pageselectCallback(page_index, jq){
	var items_per_page = 3;
	var max_elem = Math.min((page_index+1) * items_per_page, jQuery('div.commententry').length);
	var new_content = '';
	
	// Iterate through a selection of the content and build an HTML string
	for(var i=page_index*items_per_page;i<max_elem;i++) {
		new_content += jQuery('div.commententry').eq(i).html();
	}
	jQuery('#Searchresult').html(new_content);
	return false;
}

/** 
 * Callback function for the AJAX content loader.
 */
function initPagination() {
	var num_entries = jQuery('div.commententry').length;
	// Create pagination element
	jQuery("#Pagination").pagination(num_entries, {
		num_edge_entries: 2,
		num_display_entries: 8,
		callback: pageselectCallback,
		items_per_page:3
	});
 }
function alignPagination() {
	var anch = jQuery('#Pagination').children().size();
	jQuery('#Pagination').css('width', anch*25+30+'px');
}
// Load HTML snippet with AJAX and insert it into the Hiddenresult element
// When the HTML has loaded, call initPagination to paginate the elements        
jQuery(document).ready(function(){      
	initPagination();
	alignPagination();
});
