﻿
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-275340-3']);
_gaq.push(['_trackPageview']);
_gaq.push(['_trackPageLoadTime']);

(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';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();


        
/// Mail Links. Matches "mailto:" in href-tags
$('a[href^="mailto:"]').live('click', function() {
    var url = $(this).attr('href').replace(/^mailto\:/i, "");
    _gaq.push(['_setAccount', 'UA-275340-3']);
    _gaq.push(['_trackEvent', 'Mail Links', $(this).attr('href').replace(/^mailto\:/i, "")]);
});
        
/// Outgoing links. Will match all anchors with different domain.
$('a[href^="http"]:not([href*="://' + document.domain + '"])').live('click', function() {
    _gaq.push(['_setAccount', 'UA-275340-3']);
    _gaq.push(['_trackEvent', 'Outgoing Links', $(this).attr('href')]);
    //_gaq.push(['_trackPageview', '/outgoing/' + $(this).attr('href')]);
});

//Documents.
TrackEventsForDocumentClicks();

function TrackEventsForDocumentClicks() {
    
    var fileEndings = new Array(
        "doc",
        "docx",
        "gif",
        "jpg",
        "pdf",
        "png",
        "ppsx",
        "ppt",
        "pptx",
        "ps",
        "rtf",
        "tif",
        "wmf",
        "xls",
        "xlsx",
        "xml",
        "zip"
    );
    for (var i = 0; i < fileEndings.length; i++) {
        TrackEventByFileExtension(fileEndings[i]);
    }
}

function TrackEventByFileExtension(FileExtension) {
    
    var docElement = $("a[href*=." + FileExtension + "]");


    docElement.bind('click', function() {
        _gaq.push(['_setAccount', 'UA-275340-3']);
        _gaq.push(['_trackEvent', 'Documents', FileExtension, $(this).attr('href')]);
    });
}
