function RT_Css(id) {
    
    // Retrieve an array of stylesheets by URL
    this.getSheets = function(frame, media) {
        if(!frame) frame = window;
        var sheets = [];
        for(var i = 0; i < frame.document.styleSheets.length; i++) {
            /*
            if(url && frame.document.styleSheets[i].href.indexOf(url) == -1) {
                continue;
            }
            */
            if(media) {
                // Normalize the media strings
                media = media.replace(/,\s*/,',');
                var sheetMedia;
                
                if(frame.document.styleSheets[i].media.mediaText) {
                    // DOM method
                    sheetMedia = frame.document.styleSheets[i].media.mediaText.replace(/,\s*/,',');
                    // Safari adds an extra comma and space
                    sheetMedia = sheetMedia.replace(/,\s*$/,'');
                } else {
                    // MSIE
                    sheetMedia = frame.document.styleSheets[i].media.replace(/,\s*/,',');
                }
                // Skip it if the media doesn't match
                if(media != sheetMedia) { continue; }
            }
            sheets.push(frame.document.styleSheets[i]);
        }
        return sheets;
    }
    
    
    // Add a rule to a stylesheet
    this.addRule = function(selector, styles, index, frame, media) {
        var declaration = '';
        
        // Build the declaration string from the style object
        for(property in styles) {
            if(!styles.hasOwnProperty(property)) { continue; }
            declaration += property + ':' + styles[property] + ';';
        }
        
        var styleSheets = typeof(frame) == 'array' ? frame : this.getSheets();
        var newIndex;
        for(var i = 0; i < styleSheets.length; i++) {
            // Add the rule
            if(styleSheets[i].insertRule) {
                // DOM2 method
                // index = length is the end of the list
                newIndex = (index >= 0 ? index : styleSheets[i].cssRules.length);
                styleSheets[i].insertRule(
                    selector + '{' + declaration + '}',
                    newIndex
                );
            } else if(styleSheets[i].addRule) {
                // MSIE way
                // index = -1 is the end of the list
                newIndex = (index >= 0 ? index  : -1);
                styleSheets[i].addRule(selector, declaration, newIndex);
            }
        }
    }
}

RT_Css.prototype = {
    
}

if(!window.RT) { window['RT'] = {}; }
window['RT']['css'] = new RT_Css();