(function($){ window.mainImgContent = function(tab,btn,img){ var flag = 0; var tablag = ($(tab).length)-1; var aftImg = $(img).eq(0); var clTime ; var img = $(img); var lis = $(tab); var tab = $(tab).each(function(i){this.i = i}).bind('mouseover focusin', function(){ if(this.i != flag){ lis.removeClass('on').eq(this.i).addClass('on'); img.css({"z-index": 1}); aftImg.css({"z-index": 2}); img.eq(this.i).css({"z-index": 10 , "opacity":0}).animate({ "opacity":1}, 'fast'); aftImg = img.eq(this.i) flag = this.i; } clearTimeout(clTime); }); var tab = $(tab).each(function(i){this.i = i}).bind('mouseout focusout', function(){ clearTimeout(clTime); if ( flag >= 2 && flag <= tablag ) { clTime = setTimeout(move_next_content,5000) } else { clTime = setTimeout(move_next_content,5000) } }); function move_next_content(present_number){ var it_num = present_number; if(present_number == null){ it_num = flag; } lis.removeClass('on'); img.css({"z-index": 1}); aftImg.css({"z-index": 2}); if (it_num >= tablag){ lis.eq(0).addClass('on'); img.eq(0).css({"z-index": 10 , "opacity":0}).stop().animate({ "opacity":1}, 'fast'); aftImg = img.eq(0); flag = 0; }else { lis.eq(it_num+1).addClass('on'); img.eq(it_num+1).css({"z-index": 10 , "opacity":0}).stop().animate({"opacity":1}, 'fast'); aftImg = img.eq(it_num+1); flag = it_num + 1; } clearTimeout(clTime); if ( flag >= 2 && flag <= tablag ) { clTime = setTimeout(move_next_content,5000) } else { clTime = setTimeout(move_next_content,5000) } } clTime = setTimeout(move_next_content,5000); } })(jQuery);