function ajax_element(element, containerSel, prevButtonSel, nextButtonSel) {
	element = $(element);
	
	var container = element.find(containerSel);
	var prevButton = element.find(prevButtonSel);
	var nextButton = element.find(nextButtonSel);
	
	var list = container.find('ul');
	
	var onClickFunc = function(event) {
		event.preventDefault();
		prevButton.unbind();
		nextButton.unbind();
		
		$.get($(this).attr('href') + 'type:ajax/', null, function(data, status) {
			data = $(data);
			var oldElems = list.children('li');
			var oldCount = oldElems.length;
			var newElems = data.find('ul > li');
			var newCount = newElems.length;
			var count = oldCount > newCount ? oldCount : newCount;
			
			container.find('.buttons').replaceWith(data.find('.buttons'));
			ajax_element(element, containerSel, prevButtonSel, nextButtonSel);
			
			list.css('overflow', 'hidden');
			list.height(list.height());
			
			oldElems.each(function(i) {
				if (this.timeout) {
					clearTimeout(this.timeout);
					this.timeout = null;
				}
				var e = $(this);
				e.stop();
				setTimeout(function() {
					e.fadeOut(300, function() {
						e.remove();
					});
				}, (oldCount-i)*100);
			});
			
			var newH = 0;
			
			newElems.each(function(i) {
				var e = $(this);
				this.timeout = setTimeout(function() {
					e.hide().appendTo(list).fadeIn(1000, function() {
					});
					newH += e.outerHeight(true);
					if (newH > list.height()) {
						list.stop().animate({height:newH}, 300);
					} else if (i == newCount - 1 && newH < list.height()) {
						list.animate({height:newH}, 300);
					}

				}, (i+1)*100+500);
			});
		}, 'html');
	};
	
	prevButton.click(onClickFunc);
	nextButton.click(onClickFunc);
	
	$('.buttons-pager').show();
}