1// from http://www.bobbyvandersluis.com/articles/dynamicCSS.php
2var pfcCSS = Class.create();
3pfcCSS.prototype = {
4  initialize: function()
5  {
6    if (!document.getElementsByTagName ||
7      !(document.createElement || document.createElementNS)) return;
8    var agt = navigator.userAgent.toLowerCase();
9    this.is_ie = ((agt.indexOf("msie") != -1) &&  (agt.indexOf("opera") == -1));
10    this.is_iewin = (is_ie &&  (agt.indexOf("win") != -1));
11    this.is_iemac = (is_ie &&  (agt.indexOf("mac") != -1));
12    if (this.is_iemac) return; // script doesn't work properly in IE/Mac
13
14    var head = document.getElementsByTagName("head")[0];
15    this.style = (typeof document.createElementNS != "undefined") ?
16      document.createElementNS("http://www.w3.org/1999/xhtml", "style") :
17      document.createElement("style");
18    this.style.setAttribute("type", "text/css");
19    this.style.setAttribute("media", "screen");
20    head.appendChild(this.style);
21
22    this.lastStyle = document.styleSheets[document.styleSheets.length - 1];
23  },
24
25  applyRule: function(selector, declaration)
26  {
27    selector = selector.split(',');
28    for ( var i = 0; i < selector.length; i++)
29    {
30      if (!this.is_iewin) {
31        var styleRule = document.createTextNode(selector[i] + " {" + declaration + "}");
32        this.style.appendChild(styleRule); // bugs in IE/Win
33      }
34      if (this.is_iewin &&  document.styleSheets &&  document.styleSheets.length > 0) {
35        this.lastStyle.addRule(selector[i], declaration);
36      }
37    }
38  }
39}