﻿jQuery(document).ready(function($) {
    // helper function - allow regex as jQuery selector
    $.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));
    };
    $('a:regex(href,\\.(zip|mp\\d+|mpe?g|pdf|docx?|pptx?|xlsx?m?|jpe?g|png|gif|tiff?)/?$\)').live('click', function(e) {
      _gaq.push(['_trackEvent', 'download', this.href.replace(/^.*\.brewin\.co\.uk\//, ''), location.pathname]);
    });
});

///////////////////
// _trackMailTo
jQuery(document).ready(function($) {
    $('a[href^="mailto"]').live('click', function(e) {
        _gaq.push(['_trackEvent', 'email', this.href.replace(/^mailto:/i, ''), location.pathname]);
    });
});

///////////////////
// _trackOutbound
jQuery(document).ready(function($) {
        $('a[href^="https"]:not([href*="//' + location.host + '"])').live('click', function(e) {
        _gaq.push(['_trackEvent', 'outbound', this.href.match(/\/\/([^\/]+)/)[1], location.pathname]);
    });
});

