(function($) { $.fn.jaccordion = function() { $(this).each(function() { var c = $(this).children().length; var d = Array(c - 1); var e = Array(c - 1); $(this).children().each(function(a) { if (a == (c - 1)) return; e[a] = $(this).position().top; d[a] = $(this).position().top - $(this).children().outerHeight() }); var f = this; $(this).children().mouseenter(function() { var a = $(f).children().index(this); var b = $(f).children().index($(f).children('[class~="current"]')); if (!$(this).hasClass('current')) { if (b > a) { for (var i = b - 1; i >= a; i--) { $($(f).children().get(i)).stop(false, false); to_top = e[i] + 'px'; $($(f).children().get(i)).animate({ top: to_top }) } } else if (b < a) { for (var i = b; i < a; i++) { $($(f).children().get(i)).stop(false, false); to_top = d[i] + 'px'; $($(f).children().get(i)).animate({ top: to_top }) } } $(f).children().removeClass('current'); $(this).addClass('current') } }) }) } })(jQuery);