(function($){ $.fn.extend({ bannerswitch: function() { return this.each(function() { if($(this).find('li').length<2) return; var zindex=50; //add z-index $(this).find('li').each(function(e){$(this).css('z-index',--zindex)}); var o = this; setInterval(function(){ if($(o).find('.shown').next().length==0) { $(o).find('.shown').css('z-index',50); $(o).find('li:first').css('display','block'); } else $(o).find('.shown').next().css('display','block'); $(o).find('.shown').animate({opacity: 'toggle'}, 1500,function() { $(this).addClass('hidden').removeClass('shown'); if($(this).next().length==0) { $(o).find('li:first').addClass('shown').removeClass('hidden'); $(this).css('z-index',parseInt($(this).prev().css('z-index'))-1); } else { $(this).next().addClass('shown').removeClass('hidden'); $(this).next().next().find('a').html(''); } }); },5000); }); } }); })(jQuery); $(".bannerswitch").bannerswitch();