﻿/// <reference path="~/Scripts/External/jquery-1.4.2.js"/>

// first, declare the two namespaces if they do not already exist
if (Adlib == null || typeof (Adlib) != "object") { var Adlib = new Object(); }
if (Adlib.View == null || typeof (Adlib.View) != "object") { Adlib.View = new Object(); }


Adlib.View.ListRecordsOverview = function () {

  var settings;
  return {

    Init: function () {

      $j(document).ready(function () {
        settings = new Object();
        settings.items_per_page = parseInt($j("#hdParItemsPerPage").val());

        $j('#ListContainer').hide();
        Adlib.View.ListRecordsOverview.initPagination();
      });
    },
    pageselectCallback: function (page_index, jq) {
      var items_per_page = settings.items_per_page;
      var offset = page_index * settings.items_per_page;
      var new_content = $j('#ListContainer li').slice(offset, offset + items_per_page).clone();
      $j('#ResultList').empty().append(new_content);
      return false;
    },
    initPagination: function () {
      var num_entries = $j('#ListContainer li').length;

      if (num_entries > 0) {
        $j('.msgNoResults').hide();
        // Create pagination element
        $j("#Pagination").pagination(num_entries,
		            {
		              num_edge_entries: 1, 		//If this number is set to 1, links to the first and the last page are always shown, independent of the current position and the visibility constraints set by num_display_entries. You can set it to bigger numbers to show more links. Default: 0
		              num_display_entries: 5, 		//Maximum number of pagination links that are visible. Set to 0 to display a simple "Previous/Next"-Navigation. Default: 10
		              callback: Adlib.View.ListRecordsOverview.pageselectCallback,
		              items_per_page: settings.items_per_page				//The number of items per page. The maximum number of pages is calculated by dividing the number of items by items_per_page (rounded up, minimum 1). Default: 10
		            }
		        );
      }
    }
  };
} ();



