$(document).ready(function() { // Preload navigation images in both on and off states. $("#Navigation img").each(function() { // Set the original source of the image. rollsrc = $(this).attr("src"); rollON = rollsrc.replace(/.gif$/ig,"_on.gif"); $("").attr("src", rollON); }); // Start of rollover function. $("#Navigation a").mouseover(function(){ imgsrc = $(this).children("img").attr("src"); matches = imgsrc.match(/_on/); // Don't rollover if already on. if (!matches) { imgsrcON = imgsrc.replace(/.gif$/ig,"_on.gif"); // Strip excension and replace with the on link. $(this).children("img").attr("src", imgsrcON); } }); $("#Navigation a").mouseout(function(){ $(this).children("img").attr("src", imgsrc); }); });