$(document).ready(function(){ $("#top-detail").each(function(){ var intervalID; var curLi; var $tabNav = $(this).find(".ui-top-tab li"); var $tabBox = $(this).find(".ui-top-tab-item"); $(this).find(".ui-top-tab li:first").addClass("current"); ; $(this).find(".ui-top-tab-item:first").addClass("ui-top-tab-item-current"); $tabNav.mouseover(function(){ curLi=$(this); intervalID=setInterval(onmouseover,2000); }); function onmouseover(){ $tabBox.removeClass("ui-top-tab-item-current"); $tabBox.eq($tabNav.index(curLi)).addClass("ui-top-tab-item-current"); $tabNav.removeClass("current"); curLi.addClass("current"); } $tabNav.mouseout(function(){ clearInterval(intervalID); }); $tabNav.click(function(){ $tabBox.removeClass("ui-top-tab-item-current"); $tabBox.eq($tabNav.index(curLi)).addClass("ui-top-tab-item-current"); $tabNav.removeClass("current"); curLi.addClass("current"); }); }); });