﻿$(function() {
    // The slashes are to ensure the period is in the url, the $ is to make sure it is the end of the url, the i is to make it case insensitive.
    filetypes = /\.doc$|\.xls$|\.exe$|\.zip$|\.pdf$|\.mp3$|\.psd$/i;
    $("a[href]").each(function() {
        var href = $(this).attr('href');
        var hrefArray = href.split('.');
        var extension = hrefArray[hrefArray.length - 1];
        // Google Urchin stuff
        // Track mailto links
        if ($(this).attr("href").match(/^mailto\:/i)) {
            var url = $(this).attr("href").replace(/^mailto\:/i, "");
            $(this).click(function() { pageTracker._trackPageview("/mailto/" + url); });
        }
        // Track external links
        else if (location.host != this.host.replace(/\:80$/i, "")) {
            var url = $(this).attr("href").replace(/^http\:\/\/(www\.)*/i, "")
            $(this).click(function() { pageTracker._trackPageview("/outgoing/" + url); });
        }
        // Track downloads (links with a given extension)
        else if (($(this).attr("href").match(filetypes)) || ($(this).parent("p").hasClass("file"))) {
            var url = $(this).attr("href");
            $(this).click(function() { pageTracker._trackPageview("/downloads/" + url); });
        }
    });
});