var internalFilters = ["moneyadviceservice.org.uk","www.moneyadviceservice.org.uk","yourmoney.moneyadviceservice.org.uk","www.yourmoney.moneyadviceservice.org.uk","divorce.moneyadviceservice.org.uk","www.divorce.moneyadviceservice.org.uk","parents.moneyadviceservice.org.uk","www.parents.moneyadviceservice.org.uk","healthcheck.moneyadviceservice.org.uk","www.healthcheck.moneyadviceservice.org.uk","tables.moneyadviceservice.org.uk","www.tables.moneyadviceservice.org.uk","tempest.moneyadviceservice.org.uk","www.tempest.moneyadviceservice.org.uk"];
function oc(a){var o = {};for(var i=0;i<a.length;i++){o[a[i]]='';}return o;}

$(document).ready(function () {
    filetypes = /\.doc$|\.xls$|\.exe$|\.zip$|\.pdf$|\.mp3$|\.psd$/i;
    $("a").live("click", function () {
        if ($(this).attr("href").match(/^mailto\:/i)) {
            var url = $(this).attr("href").replace(/^mailto\:/i, "");
            _gaq.push(['_setDomainName', document.location.hostname]);
            _gaq.push(["_trackEvent", "Mailto", "Click", url])
        } else if (location.host != this.host.replace(/\:80$/i, "")) {
            var url = this.host.replace(/\:80$/i, "");
			if (url in oc(internalFilters)){}else{
				_gaq.push(['_setDomainName', document.location.hostname]);
				_gaq.push(["_trackEvent", "External Links", "Click", url])
			}
        } else if ($(this).attr("href").match(filetypes)) {
            var host = location.host.replace(/\./, "\\.");
            var pattern = new RegExp('^(http\:\/\/)*(www\.)*(' + host + ')*\/', 'i');
            var url = $(this).attr("href").replace(pattern, "");
            var extension = url.substr((url.lastIndexOf('.')) + 1, url.length).toUpperCase();
            _gaq.push(['_setDomainName', document.location.hostname]);
            _gaq.push(["_trackEvent", "Downloads", extension, url])
        }
    })
});
