$(document).ready(function () {
    $('a').each(function () {
        var href = $(this).attr('href');
        var filetypes = /\.(zip|exe|pdf|doc|xls|ppt|mp3|eps|docx|rar|csv|gz|dmg|xml)$/i;

        if (href) {
            //Website
            if ((href.match(/^https?\:/i)) && (!href.match(document.domain)) && (!href.match(filetypes))) {
                $(this).click(function () {
                    var webLink = href.replace(/^https?\:\/\//i, '');
                    if (typeof (intLinkDomains) != 'undefined' && webLink.match(intLinkDomains)) {
                        if (webLink.match(/shop\./i)) {
                            _gaq.push(['_trackEvent', 'Internal Link Click', 'Shop', webLink]);
                        }
                        _gaq.push(['_link', href]); return false;
                    }
                    else {
                        _gaq.push(['_trackEvent', 'External Link Click', 'Web', webLink]);
                    }

                });
            };

            //E-mail
            if (href.match(/^mailto\:/i)) {
                $(this).click(function () {
                    var mailLink = href.replace(/^mailto\:/i, '');
                    _gaq.push(['_trackEvent', 'External Link Click', 'Email', mailLink]);
                });
            }

            //File
            if (href.match(filetypes)) {
                $(this).click(function () {
                    var extension = (/[.]/.exec(href)) ? /[^.]+$/.exec(href) : undefined;
                    _gaq.push(['_trackEvent', 'External Link Click', 'Download - ' + extension, href]);
                });
            }

        }

    });

});

