$(function() { // jQuery syntax $(".rollover").each(function() { // assumes rollover extensions are "_on" and "_off" if ($(this).attr("src").indexOf(".gif") != -1) { imgExt = ".gif"; } else { imgExt = ".jpg"; } $(this).hover(function() { alsoRollIt = false; $(this).attr("src",$(this).attr("src").substr(0,$(this).attr("src").lastIndexOf('/')) + "/" + $(this).attr("id") + "_on" + imgExt); if ($(this).attr("class") != undefined) { if ($(this).attr("class").indexOf("also_") != -1) { alsoRollIt = true; newRegExp = new RegExp(/also_\w*/); newRegExpMatch = newRegExp.exec($(this).attr("class")); newRegExpMatch = String(newRegExpMatch); newRegExpMatch = newRegExpMatch.substr(5); if ($("#" + newRegExpMatch).attr("src").indexOf(".gif") != -1) { imgExt = ".gif"; } else { imgExt = ".jpg"; } $("#" + newRegExpMatch).attr("src",$("#" + newRegExpMatch).attr("src").substr(0,$("#" + newRegExpMatch).attr("src").lastIndexOf('/')) + "/" + newRegExpMatch + "_on" + imgExt); } } },function() { $(this).attr("src",$(this).attr("src").substr(0,$(this).attr("src").lastIndexOf('/')) + "/" + $(this).attr("id") + "_off" + imgExt); if (alsoRollIt == true) { $("#" + newRegExpMatch).attr("src",$("#" + newRegExpMatch).attr("src").substr(0,$("#" + newRegExpMatch).attr("src").lastIndexOf('/')) + "/" + newRegExpMatch + "_off" + imgExt); } }); }); });