$.fn.rotate = function (delay) { var rotators = this, n = this.length, current = 0, timer = null; rotators.hide().eq(current).show(); timer = setInterval(function () { current++; if (current == n) current = 0; rotators.hide().eq(current).show(); }, delay); return rotators; };