Prototype.preloadCssImages = function() {
var allImgs = [];
$A(document.styleSheets).each(function(sheet) {
var cssPile = '',
csshref = sheet.href || window.location.href,
baseURLarr = csshref.split('/');
baseURLarr.pop();//remove file path from baseURL array
var baseURL = baseURLarr.join('/'); //create base url for the images in this sheet (css file's dir)
if (baseURL) baseURL += '/'; //tack on a / if needed
if (sheet.cssRules) {
$A(sheet.cssRules).each(function(rule) {
cssPile += rule.cssText;
});
} else cssPile += sheet.cssText;
//parse cssPile for image urls and load them into the DOM
cssPile.gsub(/[^\(]+\.(?:gif|jpg|jpeg|png)/, function(match) { //reg ex to get a string of between a "(" and a ".filename"
var url = match[0];
allImgs.push(new Image());
allImgs.last().src = (url[0] == '/' || url.match('http://')) ?
url : baseURL + url; //set src either absolute or rel to css dir
});
});
return allImgs;
};