/**
 * @author ricky
 */
var css = {
	stylesheets: [],
	include: function(cssFile){
		if (cssFile.trim() == '') {
			return;
		}
		if (!this.stylesheets.length) {
			this.findCSSLinks();
		}
		if (!this.stylesheets.contains(cssFile)) {
			new Request({
				url: '/css/' + cssFile + '.css',
				method: 'get',
				async: false,
				onSuccess: function(responseText){
					css.writeCSSTitles(cssFile);
					css.addStyleSheet(responseText);
				}
			}).send();
		}
	},
	findCSSLinks: function(){
		var css_links = $$('link[type^=text/css]');
		for (var i = 0; i < css_links.length; i++) {
			if ($chk(css_links[i])) {
				var matches = css_links[i].get('href').match(/^\/css\/([0-9a-z_\/\.]+)\.css$/);
				if (matches && matches.length) {
					this.writeCSSTitles(matches[1]);
				}
			}
		}
	},
	writeCSSTitles: function(css){
		if (!this.stylesheets.contains(css)) {
			this.stylesheets.push(css);
		}
	},
	addStyleSheet: function(css){
		var head = $$('head')[0];
		if (Browser.Engine.name != 'trident') {
			new Element('style', {
				'text': css
			}).inject(head);
		}
		else {
			var stylesheet = document.createStyleSheet();
			stylesheet.cssText = css;
		}
	}
}

