(function($) {
    $.fn.xsolonInlineCSS = function(settings) {

        return this.each(function() {

            //TODO: provide settings to set media, id etc...
            $('head').append("<style type='text/css'></style>");

            var newStyleSheet = document.styleSheets[document.styleSheets.length - 1];

            //Raw css from the element
            var oo = $(this);            
            var text = oo.val().replace(/^\s+|\s+$/g, ""); //Trim
            if (text == '')
                text=oo.text();
            //remove line breaks
            text = text.replace(new RegExp("\\n", "g"), "");

            var pos = text.indexOf("}");

            // add one rule at a time
            while (pos > 0) {
                var rule = text.substring(0, pos + 1);
                text = text.substring(pos + 1);

                if (newStyleSheet.cssRules != null) //Firefox
                    newStyleSheet.insertRule(rule, newStyleSheet.cssRules.length);
                else if (newStyleSheet.rules != null) { //IE
                    var selector = rule.substring(0, rule.indexOf('{'));
                    var innerStyle = rule.substring(rule.indexOf('{') + 1, rule.indexOf('}'));
                    newStyleSheet.addRule(selector, innerStyle);
                }

                pos = text.indexOf("}");
            }
            //newStyleSheet.cssText = text; //Only works in IE, but cssText is still available in Firefox -> Can't use probe                                    
        }); //end main each
    }; // end plugin
})($);