var portion = 3; var total = 0; var position = 0; var parent = '131'; var exclude = ''; jQuery(document).ready(function(){ jQuery.ajax({ type: "GET", url: "http://"+window.location.hostname+'/ajax/sections_navigation.php', data: { getTotal: 1, parent: parent, exclude: exclude } }) .done(function( data ) { total = data; BuildStudies(); } ); }); function CheckNavigation() { if (position == 0) { jQuery('.listblock .studies_navigation .prev').hide(); } else { jQuery('.listblock .studies_navigation .prev').show(); } if (position + portion >= total) { jQuery('.listblock .studies_navigation .next').hide(); } else { jQuery('.listblock .studies_navigation .next').show(); } } function BuildStudies() { CheckNavigation(); var limit = portion; if (position + portion > total) { limit = total - position; } jQuery.ajax({ type: "GET", url: "http://"+window.location.hostname+'/ajax/sections_navigation.php', data: { getStudies: 1, start: position, limit: limit, parent: parent, exclude: exclude } }) .done(function( data ) { jQuery('.listblock .item').add('.listblock .sep').remove(); jQuery('.listblock .hdr').after(data); } ); } function SectionsNavigationNext() { if (position + portion < total ) { position += portion; } BuildStudies(); } function SectionsNavigationPrev() { if (position >= portion ) { position -= portion; } BuildStudies(); }