var UNICAEXTERNAL = (function () {
    // private variables
    var reg = /^#.*/, regjs = /^javascript.*/;
    // TODO: adda regex to match javascript : void()
    function TagExternal(t) {
        ntptEventTag('ev=external_link&link=' + encodeURIComponent(t.href));
    }

    function TagInternal(t) {
        // these are considered custom tags but they look like internal links. So skip tagging in these classes exist.
        // did the check in here for better performance, can't put it in loop below
        ntptEventTag('ev=internal_links&link=' + encodeURIComponent(t.href));
    }

    return (function autotag() {
        // Auto Tagging
        $('body a').filter(function () {
            var anc = this, u = anc.href, janc = $(this);
            // rnav returns 1 if link is in right nav. don't need to tag right nav links
            // since we are already custom tagging them.
            if (u) {
                if (anc.hostname && anc.hostname !== location.hostname) {
                    // Outbound links
                    janc.click(function (e) {
                        TagExternal(anc);
                    });
                } else {
                    // Internal links
                    // h: href should not be a hash - only tag normal links to pages
                    var h = anc.getAttribute('href').match(reg);
                    var hjs = anc.getAttribute('href').match(regjs);
                    if ((h === null) && (hjs === null)) {
                        if (((anc.getAttribute('onclick') + "").indexOf('IntLinTracking') == -1) &&
                            ((anc.getAttribute('onclick') + "").indexOf('Internal Links') == -1)) {
                            $(janc).bind('click', function (e) {
                                TagInternal(this);
                            });
                        }
                    }
                }
            }
        });
    } ());
} ());
