$(document).ready(function() {
		$('.nextOffers').bind('click',function() {		
		
			var trigger = this;
		
			var currentPage = $(this).parents('.dosblanco:first').find('.dealsPage').not('.no-display');
			currentPage.fadeOut('slow',function() {
				$(this).addClass('no-display');
				currentPage.next().fadeIn('slow',function() {
					$(this).removeClass('no-display');
				});
				if(currentPage.next('.dealsPage').next('.dealsPage').length == 0) {
					$(trigger).hide();
				}
				$(trigger).parent().prev().prev().find('a').show();
			});
			
			return false;
			
		});
		
		$('.prevOffers').bind('click',function() {		
			var trigger = this;
			var currentPage = $(this).parents('.dosblanco:first').find('.dealsPage').not('.no-display');
			currentPage.fadeOut('slow',function() {
				$(this).addClass('no-display');
				currentPage.prev().fadeIn('slow',function() {
					$(this).removeClass('no-display');
				});
				if(currentPage.prev('.dealsPage').prev('.dealsPage').length == 0) {
					$(trigger).hide();
				}
				$(trigger).parent().next().next().find('a').show();
			});
			
			return false;
			
		});
		
		var currentStudentsPage = 1;
		var nextStudents = function() {		
		
			currentStudentsPage++;
			
			$.get('/ajax/get-requests.php',{'lng':lang,'country':country,'city':city,'page':currentStudentsPage},srProcess,'json');
			
			return false;
			
		}
		
		var prevStudents = function() {		
		
			currentStudentsPage--;
			
			$.get('/ajax/get-requests.php',{'lng':lang,'country':country,'city':city,'page':currentStudentsPage},srProcess,'json');
			
			return false;
			
		}
		
		$('.nextStudents').bind('click',nextStudents);
		$('.prevStudents').bind('click',prevStudents);
		
		function srProcess(data) {
			$('.studentsRequests').replaceWith(data.html);
			
			if(data.numpages == currentStudentsPage) {
				$('.nextStudents').hide();
			} else {				
				$('.nextStudents').bind('click',nextStudents);
				$('.nextStudents').show();
			}
			
			if(currentStudentsPage > 1) {
				$('.prevStudents').bind('click',prevStudents);
				$('.prevStudents').show();
			} else {
				$('.prevStudents').hide();
			}
			
		}
		
});
