As soon as the picture comes out, it will start flashing after 5 seconds, and then stop.
var inter={}; var i=0; $(document).ready(function(){ $("a").each(function(index,item){ $(this).bind().click(function(){ i=index; if(inter!=null || inter.length>0){ window.clearInterval(inter); } window.setTimeout(function(){ inter=window.setInterval(function(){ $("img").eq(i).show().fadeOut(100).fadeIn(100);},500); window.setTimeout(function(){ window.clearInterval(inter); },5000); },5000); }); }); window.setTimeout(function(){ inter=window.setInterval(function(){ $("img").eq(i).show().fadeOut(100).fadeIn(100);},500); window.setTimeout(function(){ window.clearInterval(inter); },5000); },5000); });