/**
 * 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 temp = [];  
    var i=1;
    var begin =(page_index * 12);
    var end = ((page_index + 1) * 12);
    $('#Productlist').empty();
    temp = $('.productItem').clone();
    temp.each(function(){
        if (begin < i && i <= end ){
        $('#Productlist').append(this);
        };
        i++;
    });
    if (end > temp.length){
    end = temp.length;
    };
    $('.productResults').html("Results: " + ( begin +1 )+ "-" + end + " of " + temp.length);
    return false;}

function initPagination() {
    var num_entries = $('#hiddenproducts div.productItem').length;
    // Create pagination element -     
    $("#Pagination").pagination(num_entries, {                
        num_edge_entries: 2,
        num_display_entries: 3,
        callback: pageselectCallback
             
    });
    // JK hide if not needed
    if($("#Pagination").length > 0){
        if(num_entries < 13) $("#Pagination")[0].style.display = "none";
    }
 }
              
$(document).ready(function(){      
    initPagination();

});
