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));
    };

	// _trackDownloads
    $('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(/^.*\/\//, '')]);
    });

	// _trackMailTo
    $('a[href^="mailto"]').live('click', function(e) {
        _gaq.push(['_trackSocial', 'email', 'send', this.href.replace(/^mailto:/i, '')]);
    });

	// _trackOutbound
    $('a[href^="http"]:not([href*="//' + location.host + '"]:not[href*=addthis.com])').live('click', function(e) {
        _gaq.push(['_trackEvent', 'outbound', 'click', this.href.match(/\/\/([^\/]+)/)[1]]);
    });
	
    // addThis Track Social
    if (typeof addthis !== "undefined") {
        addthis.addEventListener('addthis.menu.share', function(e) {
            _gaq.push(['_trackSocial', 'addthis', e.data.service]);
        });
    }
});

if(document.location.protocol=='http:'){
 var Tynt=Tynt||[];Tynt.push('aOdHso0vWr3RYXab7jrHcU');Tynt.i={"ap":"Read more from Stephane Hamel:","st":true,"su":false};
 (function(){var s=document.createElement('script');s.async="async";s.type="text/javascript";s.src='http://tcr.tynt.com/ti.js';var h=document.getElementsByTagName('script')[0];h.parentNode.insertBefore(s,h);})();
}

