$(document).ready(function(){

    var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
    $.getScript(gaJsHost + "google-analytics.com/ga.js", function(){

        try {
            window.firstTracker = _gat._getTracker("UA-1862709-9");
            firstTracker._trackPageview();
            window.defTracker = _gat._getTracker("UA-12197985-1");
            defTracker._trackPageview();
        } catch(err) {}
        
        var filetypes = /\.(zip|exe|pdf|doc*|xls*|ppt*|mp3|app|rar|dmg)$/i;

        $('a').each(function(){
            var href = $(this).attr('href');

            if ((href.match(/^https?\:/i)) && (!href.match(document.domain))){
            // mejor dejar los links como estaban
            }
            else if (href.match(/^mailto\:/i)){
                $(this).click(function() {
                    var mailLink = href.replace(/^mailto\:/i, '');
                    firstTracker._trackEvent('mailto', 'Click', mailLink);
                    defTracker._trackEvent('mailto', 'Click', mailLink);
                });
            }
            else if (href.match(filetypes)){
                $(this).click(function() {
                    var extension = (/[.]/.exec(href)) ? /[^.]+$/.exec(href) : undefined;
                    var filePath = href.replace(/^https?\:\/\/(www.)carnemag\.com\//i, '');
                    firstTracker._trackEvent('Download', 'Click - ' + extension, filePath);
                    defTracker._trackEvent('Download', 'Click - ' + extension, filePath);
                });
            }
        });
    });
});