//MooTools More, <http://mootools.net/more>. Copyright (c) 2006-2008 Valerio Proietti, <http://mad4milk.net>, MIT Style License.

/*
Temporary fix to enable onload event for CSS assets

By Stickman (http://the-stickman.com)
*/

Asset.css = function(source, properties){

	// Create a style element instead of a link element
	var style_node = new Element('style', $merge({
		'media': 'screen', 'type': 'text/css'
	}, properties)).inject(document.head);
	// Not sure why this is needed, but it is
	style_node.onload = properties.onload;
	delete properties.onload;

	// Fetch CSS using XHR
	var request = new Request
	(
		{
			method: 'get',
			url: source,
			style_node:style_node,
			onSuccess:function( css_text ){
				// Set the CSS
				// From http://yuiblog.com/blog/2007/06/07/style/
				if (this.styleSheet) {
					this.styleSheet.cssText = css_text;
				} else {
					this.appendChild(document.createTextNode(css_text));
				}
				this.onload();
			}.bind( style_node )
		}
	);
	request.send();

	return style_node;
};