var tagger = { cache: {}, exprs: [ {re: /^(canada|united-states|australia|united-kingdom|alabama|alaska|arizona|arkansas|california|colorado|connecticut|delaware|florida|georgia|hawaii|idaho|illinois|indiana|iowa|kansas|kentucky|louisiana|maine|maryland|massachusetts|michigan|minnesota|mississippi|missouri|montana|nebraska|nevada|new-hampshire|new-jersey|new-mexico|new-york|north-carolina|north-dakota|ohio|oklahoma|oregon|pennsylvania|rhode-island|south-carolina|south-dakota|tennessee|texas|utah|vermont|virgina|washington|west-virgina|wisconsin|wyoming)$/, replace: function(img) { return "http://images.taxqueries.com/flags/"+img+".gif"; } } ], paint: function() { $(".post-tag").each(function() { var $tag = $(this), totest = $tag.text().replace(/^\s+|\s+$/g,''); $tag.find("img").remove(); if (!tagger.cache.hasOwnProperty(totest)) { tagger.cache[totest] = []; $.each(tagger.exprs,function(i, tester) { if (totest.match(tester.re)) { tagger.cache[totest].push(" "); } }); } $.each(tagger.cache[totest],function(i,img) { $tag.prepend(img); }); }); }, register: function() { $(tagger.paint); } }; tagger.register();