$.fn.accordion = function () { var a = $(this); var c = 3; var e = null; a.children("li").each(function (f) { $(this).css("left", f * 50) }); function b(f) { a.children("li").eq(f).stop().animate({ left: f * 53 + "px" }, 200); a.children("li").eq(f).nextAll().each(function (g) { $(this).stop().animate({ left: 248 + f * 53 + g * 53 + "px" }, 200) a.children("li").eq(f).nextAll().removeClass('on'); }); a.children("li").eq(f).prevAll().each(function (g) { $(this).addClass('on'); $(this).stop().animate({ left: (f - g - 1) * 53 + "px" }, 200) a.children("li").eq(f).prevAll().removeClass('on'); }) a.children("li").eq(f).addClass('on'); } a.children("li").mouseenter(function () { var f = a.children("li").index(this); c = f; b(f); clearTimeout(e); d() }); function d() { e = setTimeout(function () { if (c >= 3) { c = 0 } else { c++ } b(c); d() }, 2000) } d() };