var twttr = window.twttr || {};
(function () {
    var A = /twitter\.com(\:\d{2,4})?\/intent\/(\w+)/,
        T = {
            tweet: true,
            retweet: true,
            favorite: true
        },
        G = "scrollbars=yes,resizable=yes,toolbar=no,location=yes",
        C = screen.height,
        P = screen.width;

    function Z(j) {
        j = j || window.event;
        var i = j.target || j.srcElement,
            d, f, c, h, g;
        while (i && i.nodeName.toLowerCase() !== "a") {
            i = i.parentNode
        }
        if (i && i.nodeName.toLowerCase() === "a" && i.href) {
            d = i.href.match(A);
            if (d) {
                f = 550;
                c = (d[2] in T) ? 420 : 560;
                h = Math.round((P / 2) - (f / 2));
                g = 0;
                if (C > c) {
                    g = Math.round((C / 2) - (c / 2))
                }
                window.open(i.href, "intent", G + ",width=" + f + ",height=" + c + ",left=" + h + ",top=" + g);
                j.returnValue = false;
                j.preventDefault && j.preventDefault()
            }
        }
    }
    if (document.addEventListener) {
        document.addEventListener("click", Z, false)
    } else {
        if (document.attachEvent) {
            document.attachEvent("onclick", Z)
        }
    }
    if (!twttr.widgets) {
        twttr.widgets = {}
    }
    if (!twttr.widgets.host) {
        twttr.widgets.host = "platform{i}.twitter.com"
    }
    if (typeof twttr.widgets.ignoreSSL === "undefined") {
        twttr.widgets.ignoreSSL = false
    }
    function Y(d) {
        var f = Q(d);
        var e = twttr.widgets.host;
        var c = e.replace("{i}", I++);
        if (I == 3) {
            I = 0
        }
        return f + "://" + c
    }
    function Q(c) {
        return (window.location.protocol.match(/s\:$/) || c) && !twttr.widgets.ignoreSSL ? "https" : "http"
    }
    function X(g) {
        var d;
        for (var c in g) {
            d = R.apply(this, c.split("."));
            for (var e = 0, f;
            (f = d[e]); e++) {
                new g[c](f).render()
            }
        }
    }
    function M(h) {
        var e;
        var f;
        var d = function () {
            if (document.readyState == "complete") {
                e()
            }
        };
        var c;
        var g = function () {
            try {
                document.documentElement.doScroll("left");
                e()
            } catch (i) {}
        };
        if (window.addEventListener) {
            e = function () {
                if (!f) {
                    f = true;
                    h()
                }
                window.removeEventListener("DOMContentLoaded", e, false);
                window.removeEventListener("load", e, false)
            };
            window.addEventListener("DOMContentLoaded", e, false);
            window.addEventListener("load", e, false)
        } else {
            if (window.attachEvent) {
                c = window.setInterval(g, 13);
                e = function () {
                    if (!f) {
                        f = true;
                        h()
                    }
                    window.clearInterval(c);
                    window.detachEvent("onreadystatechange", d);
                    window.detachEvent("onload", e)
                };
                window.attachEvent("onreadystatechange", d);
                window.attachEvent("onload", e)
            }
        }
    }
    function R(c, h) {
        var g, j = [],
            d, f;
        try {
            if (document.querySelectorAll) {
                j = document.querySelectorAll(c + "." + h)
            } else {
                if (document.getElementsByClassName) {
                    g = document.getElementsByClassName(h);
                    for (d = 0;
                    (f = g[d]); d++) {
                        if (f.tagName.toLowerCase() == c) {
                            j.push(f)
                        }
                    }
                } else {
                    g = document.getElementsByTagName(c);
                    var l = new RegExp("\\b" + h + "\\b");
                    for (d = 0;
                    (f = g[d]); d++) {
                        if (f.className.match(l)) {
                            j.push(f)
                        }
                    }
                }
            }
        } catch (k) {}
        return j
    }
    function V(c) {
        return encodeURIComponent(c).replace(/\+/g, "%2B")
    }
    function F(c) {
        return decodeURIComponent(c)
    }
    function N(e) {
        var d = [];
        for (var c in e) {
            if (e[c] !== null && typeof e[c] !== "undefined") {
                d.push(V(c) + "=" + V(e[c]))
            }
        }
        return d.sort().join("&")
    }
    function U(f) {
        var h = {},
            e, g, d, c;
        if (f) {
            e = f.split("&");
            for (c = 0;
            (d = e[c]); c++) {
                g = d.split("=");
                if (g.length == 2) {
                    h[F(g[0])] = F(g[1])
                }
            }
        }
        return h
    }
    function J(d, e) {
        for (var c in e) {
            d[c] = e[c]
        }
        return d
    }
    function W(d) {
        var c;
        if (d.match(/^https?:\/\//)) {
            return d
        } else {
            c = location.host;
            if (location.port.length > 0) {
                c += ":" + location.port
            }
            return [location.protocol, "//", c, d].join("")
        }
    }
    function B() {
        var c = document.getElementsByTagName("link");
        for (var d = 0, e;
        (e = c[d]); d++) {
            if (e.getAttribute("rel") == "canonical") {
                return W(e.getAttribute("href"))
            }
        }
        return null
    }
    function L(e) {
        var f = [];
        for (var d = 0, c = e.length; d < c; d++) {
            f.push(e[d])
        }
        return f
    }
    function E() {
        var d = document.getElementsByTagName("a"),
            k = document.getElementsByTagName("link"),
            c = /\bme\b/,
            f = /^https?\:\/\/(www\.)?twitter.com\/(#!\/)?([a-zA-Z0-9_]+)\/?$/,
            j = L(d).concat(L(k)),
            h, m, e;
        for (var g = 0, l;
        (l = j[g]); g++) {
            m = l.getAttribute("rel");
            e = l.getAttribute("href");
            if (m && e && m.match(c) && (h = e.match(f))) {
                return h[3]
            }
        }
    }
    var H = document.title,
        O = encodeURI(location.href),
        I = 0,
        a = {
            en: {
                vertical: [55, 62],
                horizontal: [110, 20],
                none: [55, 20]
            },
            de: {
                vertical: [67, 62],
                horizontal: [110, 20],
                none: [67, 20]
            },
            es: {
                vertical: [64, 62],
                horizontal: [110, 20],
                none: [64, 20]
            },
            fr: {
                vertical: [65, 62],
                horizontal: [110, 20],
                none: [65, 20]
            },
            it: {
                vertical: [55, 62],
                horizontal: [110, 20],
                none: [55, 20]
            },
            ko: {
                vertical: [55, 62],
                horizontal: [110, 20],
                none: [55, 20]
            },
            ja: {
                vertical: [80, 62],
                horizontal: [130, 20],
                none: [80, 20]
            }
        },
        K = {
            en: 1,
            de: 1,
            es: 1,
            fr: 1,
            it: 1,
            ko: 1,
            ja: 1
        },
        D = {
            vertical: 1,
            horizontal: 1,
            none: 1
        },
        b = {
            en: "Twitter For Websites: Tweet Button",
            de: "Twitter fÃ¼r Webseiten: Tweet-SchaltflÃ¤che",
            es: "Twi`tter para sitios web: BotÃ³n para Twittear",
            fr: 'Twitter pour votre site web : bouton "Tweeter"',
            it: "Tweeter per i siti web: Bottone Tweet",
            ko: "Twitter ì›¹ë²„ì „: íŠ¸ìœ— ë²„íŠ¼",
            ja: "WEBã‚µã‚¤ãƒˆå‘ã‘Twitter: ãƒ„ã‚¤ãƒ¼ãƒˆãƒœã‚¿ãƒ³"
        };
    twttr.TweetButton = function (g) {
        this.originElement = g;
        var d = g.href.split("?")[1],
            f = d ? U(d) : {},
            c = f.count || g.getAttribute("data-count"),
            e = f.lang || g.getAttribute("data-lang");
        this.text = f.text || g.getAttribute("data-text") || H;
        this.via = f.via || g.getAttribute("data-via") || E();
        this.url = f.url || g.getAttribute("data-url") || B() || O;
        this.statusID = f.status_id || g.getAttribute("data-status-id");
        this.related = f.related || g.getAttribute("data-related");
        this.counturl = f.counturl || g.getAttribute("data-counturl");
        this.searchlink = f.searchlink || g.getAttribute("data-searchlink");
        this.placeid = f.placeid || g.getAttribute("data-placeid");
        if (!D[c]) {
            c = "horizontal"
        }
        this.count = c;
        if (!K[e]) {
            e = "en"
        }
        this.lang = e
    };
    J(twttr.TweetButton.prototype, {
        parameters: function () {
            var c;
            if (this.statusID) {
                c = {
                    status_id: this.statusID
                }
            } else {
                c = {
                    text: this.text,
                    url: this.url,
                    via: this.via,
                    related: this.related,
                    count: this.count,
                    lang: this.lang,
                    counturl: this.counturl,
                    searchlink: this.searchlink,
                    placeid: this.placeid
                }
            }
            c._ = (new Date()).getTime();
            return N(c)
        },
        render: function () {
            if (!twttr.TweetButton.fragment) {
                twttr.TweetButton.fragment = document.createElement("div");
                twttr.TweetButton.fragment.innerHTML = '<iframe allowtransparency="true" frameborder="0" scrolling="no" tabindex="0" class="twitter-share-button twitter-count-' + this.count + '"></iframe>'
            }
            var d = twttr.TweetButton.fragment.firstChild.cloneNode(false);
            d.src = Y() + "/widgets/tweet_button.html?" + this.parameters();
            var e = a[this.lang][this.count];
            d.style.width = e[0] + "px";
            d.style.height = e[1] + "px";
            d.title = b[this.lang];
            var c = this.originElement.parentNode;
            if (c) {
                c.replaceChild(d, this.originElement)
            }
        }
    });
    var S = {
        "a.twitter-share-button": twttr.TweetButton
    };
    X(S);
    M(function () {
        X(S)
    })
}());
