(function($)
{
  $.loadXCSS = function(o, cb)
	{		
	  if ($.isArray(o))
		{
		  $.each(o, function(i, v) { $.loadXCSS(v, cb) });
			return this
		}
	  else if (typeof o == 'string')
		{
		  try { o = eval('(' + o + ')') }
			catch(e)
			{
				$.ajax({ dataType: 'text', url: o, success: function(o) {  $.loadXCSS(o, cb) } });
				return this
			}
		}

		var props = ['background-attachment', 'background-color', 'background-image', 'background-position', 'background-repeat', 'background', 'border-collapse', 'border-color', 'border-spacing', 'border-style', 'border-top', 'border-right', 'border-bottom', 'border-left', 'border-top-color', 'border-right-color', 'border-bottom-color', 'border-left-color', 'border-top-style', 'border-right-style', 'border-bottom-style', 'border-left-style', 'border-top-width', 'border-right-width', 'border-bottom-width', 'border-left-width', 'border-width', 'border', 'bottom', 'clear', 'clip', 'color', 'content', 'cursor', 'display', 'float', 'font-family', 'font-size', 'font-style', 'font-variant', 'font-weight', 'font', 'height', 'left', 'letter-spacing', 'line-height', 'list-style-image', 'list-style-position', 'list-style-type', 'list-style', 'margin-right', 'margin-left', 'margin-top', 'margin-bottom', 'margin', 'max-height', 'max-width', 'min-height', 'min-width', 'outline-color', 'outline-style', 'outline-width', 'outline', 'overflow', 'padding-top', 'padding-right', 'padding-bottom', 'padding-left', 'padding', 'page-break-after', 'page-break-before', 'page-break-inside', 'position', 'right', 'table-layout', 'text-align', 'text-decoration', 'text-indent', 'text-transform', 'top', 'vertical-align', 'visibility', 'white-space', 'width', 'word-spacing', 'z-index'],
				combs = ['>', '+', '~'], 
				vars = {}, 
				rules = [];

		(function(d, i, n)
		{
			var f = arguments.callee, r = [], j = i;
			
			$.each(d, function(k, v)
			{
				get = function(r) { $.each(vars, function(k, v) { r = r.toString().replace(k, v) }); return r };
				has = function(a, v) { if ($.browser.msie) { for (var i = 0; i < a.length; i++) { if (a[i] == v) return true } return false } else return a.indexOf(v) >= 0 };
				
				var c = (k = $.trim(k)).charAt(0);
				if ($.isFunction(v)) v = v();
				
				if (c == '$') vars[k] = v.toString();
				else if (c == '-' || has(props, k)) r.push(k + ': ' + get(v) + ';');
				else
				{
					k = (n || '') + (has(combs, c) ? ' ': '') + (k.substr(0, 2) == '>>' ? $.trim(k.substr(2)): k);
					if (typeof v == 'object') i = f(v, ++i, k);
					else if (typeof v == 'string') rules[++i - 1] = [k, get(v)];
				}
			});
		
			if (r.length > 0) rules[j - 1] = [n, r.join(' ')];
			
			return i;
		})
		(o, 0);

		var s = $('<style/>').attr('type', 'text/css').appendTo('head').get(0)[$.browser.msie ? 'styleSheet': 'sheet'];
		$.each(rules, function(i, v)
		{
			if ($.browser.msie) s.addRule(v[0], v[1], i); 
			else s.insertRule(v[0] + ' {' + v[1] + '}', i)
		});

		if ($.isFunction(cb)) cb();
	  return this;
	}
	
	$("link[type='text/xcss']").each(function()
	{
		$.loadXCSS(this.href);
	});
})
(jQuery);