function loadCSS() {
	var s = document.getElementsByTagName('link');
	for(var i= 0; i<s.length; i++) {
		if(s[i].rel=='stylesheet') {
			$.get(s[i].href, parseCSS);
		}
	}
}

function parseCSS(css) {
	var reg = /@importrule\s+['"]?([^'";]*)/gi;
	while ((importedRule = reg.exec(css)) != null) {					
		applyCSS(importedRule[1], getSelector(css,importedRule.index));			
	}		
}

function getSelector(css, index) {
	while(index>=0 && css.charAt(index)!='{')
		index--;
	var end = index;
	while(index>=0 && css.charAt(index)!='}')
		index--;		
	return css.substring(index+1,end).replace(/\s+/g,''); 
}

function applyCSS(importedRule, selector) {		
	if(importedRule.charAt(0)==".") {			
		$(selector).addClass(importedRule.substring(1));
		if(cache[importedRule]) {
			applyCSS(cache[importedRule],selector);
		}
		cache[selector] = importedRule;
	}
}
cache={};
$(document).ready(loadCSS);
