/*
 * netj.org Javascript for final page customizations
 * Author: Jaeho Shin <netj@sparcs.org>
 * Created: 2010-05-14
 */

function hasSVGSupport() {
    // check if browser supports SVG
    if (navigator.mimeTypes && navigator.mimeTypes.length > 0)
        if (navigator.mimeTypes["image/svg+xml"] ||
                navigator.mimeTypes.item("image/svg+xml")) {
            // WebKit(Safari, Chrome) and Presto(Opera) based browser can render SVG in <img>s
            // I myself checked WebKit version, and See below for Opera/Presto:
            // http://en.wikipedia.org/wiki/Presto_(layout_engine)
            var ua = navigator.userAgent;
            var m;
            m = ua.match(/WebKit\/(\d*)/);
            if (m && m[1] >= 531)
                return true;
            m = ua.match(/Presto\/(\d+\.\d+)/);
            if (m && parseFloat(m[1]) >= 2.1)
                return true;
        }
    return false;
}

function replaceSiteIconWithSVG() {
    if (hasSVGSupport()) {
        var siteIcon = document.getElementById("site-icon");
        if (siteIcon && siteIcon.tagName.toLowerCase() == "img") {
            siteIcon.src = "netj.svg";
            siteIcon.type = "image/svg+xml";
        }
    }
}
replaceSiteIconWithSVG();


// localize #reaction-info set by DISQUS
if (navigator.language && navigator.language.match(/^ko/))
    $(document).ready(function() {
            var updateReactionInfo;
            updateReactionInfo = function() {
                var t = this.innerText;
                if (!t)
                    t = this.innerHTML;
                var m = t.match(/(\d+) Comments and (\d+) Reactions/);
                if (m)
                    jQuery(this).text("댓글 " + m[1] + "개와 반응 " + m[2] + "개");
                else
                    setTimeout(updateReactionInfo, 500);
            };
            $("#reaction-info a").each(updateReactionInfo);
        });

