var UAAccount = 'UA-4027823-1';
var crossDomains = '(miamiadschool.com.br|masespm.com.br|mas.espm.br|espm.br)'; // regex matching the list of top domains you own
var baseDomain = location.hostname.match(RegExp(crossDomains + '$'));
baseDomain = (baseDomain ? baseDomain[1].replace(/\:\d+/, '') : location.hostname);
var _gaq = _gaq || [];
_gaq.push(['_setAccount', UAAccount]); // change the UA account!
_gaq.push(['_setDomainName', baseDomain]);
_gaq.push(['_setAllowLinker', true]);
_gaq.push(['_trackPageview']);

_gaq.push(['masespm._setAccount', 'UA-13180689-']); // change the UA account!
_gaq.push(['masespm._setDomainName', baseDomain]);
_gaq.push(['masespm._setAllowLinker', true]);
_gaq.push(['masespm._trackPageview']);

(function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();

jQuery(document).ready(function($){
	$.expr[':'].regex = function(e, i, m) {
        var mP = m[3].split(','),
            l = /^(data|css):/,
            a = {
                method: mP[0].match(l) ? mP[0].split(':')[0] : 'attr',
                property: mP.shift().replace(l, '')
            },
            r = new RegExp(mP.join('').replace(/^\s+|\s+$/g, ''), 'ig');
        return r.test($(e)[a.method](a.property));
    };

    // for any link starting with http, but not pointing to the current domain or any of its subdomains, but matching one of our tracked domains...
    $('a:regex(href,' + crossDomains + ')').live('click', function(e) {
        if (this.href.match(crossDomains)[1] != baseDomain) { 
            var t = _gat._getTrackerByName();
            this.href = t._getLinkerUrl(this.href);
        }
    });

    // helper function - allow regex as jQuery selector
    $('a:regex(href,"\\.(zip|mp\\d+|mpe*g|pdf|docx*|pptx*|xlsx*|jpe*g|png|gif|tiff*)")$').live('click', function(e) {
        _gaq.push(['_trackEvent', 'download', 'click', this.href.replace(/^.*\/\//, '')]);
		_gaq.push(['masespm._trackEvent', 'download', 'click', this.href.replace(/^.*\/\//, '')]);
    });
     $('a[href^="mailto"]').live('click', function(e) {
        _gaq.push(['_trackSocial', 'email', 'send', this.href.replace(/^mailto:/i, '')]);
		_gaq.push(['masespm._trackSocial', 'email', 'send', this.href.replace(/^mailto:/i, '')]);
    });
    $('a[href^="http"]:not([href*="//' + location.host + '"])').live('click', function(e) {
        _gaq.push(['_trackEvent', 'outbound', 'click', this.href.match(/\/\/([^\/]+)/)[1]]);
		_gaq.push(['masespm._trackEvent', 'outbound', 'click', this.href.match(/\/\/([^\/]+)/)[1]]);
    });
});
