
// Add various classes to the document body before the <body> tag exists in the DOM
(function () {
    var interval;
    var isCompatible = true;
    var agent = navigator.userAgent.toLowerCase();
    var version = (agent.match( /.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/ ) || [])[1];
    var browser = {
        ie: /msie/.test(agent) && !/opera/.test(agent),
        mozilla: /mozilla/.test(agent) && !/(compatible|webkit)/.test(agent),
        safari: /webkit/.test(agent),
        opera: /opera/.test(agent),
        konqueror: /KDE/.test(navigator.vendor)
    };
    
    // For easy CSS browser detection
    // Ex. for IE6, adds following classes: ie ie6 ie55-up ie6-up ie6-down ie7-down
    if (browser.ie) {
        var v = parseFloat(version);
        var n = [5.5, 6, 7];
        var c = ' ie ie'+v;
        
        // Add the ieN-down and ieN-up classes
        for (var i = n.length; i--;) {
            if (n[i] >= v) {
                c += ' ie'+n[i]+'-down';
            }
            if (n[i] <= v) {
                c += ' ie'+n[i]+'-up';
            }
        }
        isCompatible = (v >= 6);
        document.documentElement.className += c.replace(/\./g, '');
    } else {
        for (var b in browser) {
            if (browser[b]) {
                document.documentElement.className += ' '+b;
            }
        }
    }
    
    // Tell the CSS that the JavaScript is initialized
    if (isCompatible) {
        document.documentElement.className += ' js';
    }
    
    // Removes the nojs class
    interval = setInterval(function () {
        var body = document.getElementsByTagName('body');
        if (body.length) {
            body[0].className = body[0].className.replace('nojs', '');
            clearInterval(interval);
        }
    }, 10);
})();
