1/**
2 *
3 * @license   GPL 2 (http://www.gnu.org/licenses/gpl.html)
4 * @author    Tom N Harris <tnharris@whoopdedo.org>
5 */
6jQuery(function (){
7  jQuery.uaMatch = function( ua ) {
8    ua = ua.toLowerCase();
9    var match = /(chrome)[ \/]([\w.]+)/.exec( ua ) ||
10        /(webkit)[ \/]([\w.]+)/.exec( ua ) ||
11        /(opera)(?:.*version|)[ \/]([\w.]+)/.exec( ua ) ||
12        /(msie) ([\w.]+)/.exec( ua ) ||
13        ua.indexOf("compatible") < 0 && /(mozilla)(?:.*? rv:([\w.]+)|)/.exec( ua ) || [];
14    return {
15        browser: match[ 1 ] || "",
16        version: match[ 2 ] || "0"
17    };
18};
19if ( !jQuery.browser ) {
20    var
21    matched = jQuery.uaMatch( navigator.userAgent ),
22    browser = {};
23    if ( matched.browser ) {
24        browser[ matched.browser ] = true;
25        browser.version = matched.version;
26    }
27    // Chrome is Webkit, but Webkit is also Safari.
28    if ( browser.chrome ) {
29        browser.webkit = true;
30    } else if ( browser.webkit ) {
31        browser.safari = true;
32    }
33    jQuery.browser = browser;
34}
35  if(jQuery.browser.msie && 8 > parseFloat(jQuery.browser.version)){
36    // Does MSIE support :before and :after ?
37    function isParentNode(p, n){
38      if(!p) return false;
39      while(n){
40        if(n == p) return true;
41        n = n.parentNode;
42      }
43      return false;
44    }
45    var q_open = Array();
46    var q_close = Array();
47    var ssheet = document.styleSheets[0];
48    for(var i=0; i<ssheet.rules.length; i++){
49      var srule = ssheet.rules[i];
50      if(srule.selectorText=='Q'){
51        var quotes = srule.style.quotes.split(' ');
52        for(var j=0; j<quotes.length; j+=2){
53          var q = quotes[j];
54          if(q.length < 3) continue;
55          var q1 = q.substring(1,q.length-1);
56          var q2 = q1;
57          if(j+1 < quotes.length){
58            q = quotes[j+1];
59            if(q.length >= 3){
60              q2 = q.substring(1,q.length-1);
61            }
62          }
63          q_open.push(q1);
64          q_close.push(q2);
65        }
66      }
67    }
68    if(q_open.length==0) q_open.push('“');
69    if(q_close.length==0) q_close.push('”');
70    var qstack = Array();
71    var qprev = null;
72    var qelems = document.getElementsByTagName('q');
73    for(var i=0; i<qelems.length; i++){
74      var q = qelems[i];
75      if(isParentNode(qprev, q)){
76        if(qprev)
77          qstack.push(qprev);
78      }else{
79        while(qstack.length > 0){
80          qprev = qstack.pop();
81          if(isParentNode(qprev, q)){
82            qstack.push(qprev);
83            break;
84          }
85        }
86      }
87      var mark_before = document.createTextNode(q_open[qstack.length % q_open.length]);
88      var mark_after = document.createTextNode(q_close[qstack.length % q_open.length]);
89      q.insertBefore(mark_before, q.firstChild);
90      q.insertBefore(mark_after);
91      qprev = q;
92    }
93    var bqelems = document.getElementsByTagName('blockquote');
94    for (var i=0; i<bqelems.length; i++){
95      var bq = bqelems[i];
96      var bq_cite = bq.getAttribute('title');
97      if (bq.className == 'citation' && bq_cite) {
98        var bq_after = document.createElement('div');
99        bq_after.setAttribute('className', 'citation_after');
100        bq_after.innerHTML = '—' + bq_cite;
101        bq.appendChild(bq_after);
102      }
103    }
104  }
105});
106