ceci peut-être?

$(document).ready(function() {
$("#ap").fn_ap();
});

$.fn.fn_ap = function() {

var that = this;
var nbSlide = 4;