﻿
/*
Automagic Google Tracking
*/
$(document).ready(function() {

    //Hyperlinks with a trackme class
    $(document).delegate("a.trackme", "click", function() {
       pageTracker._trackEvent('Hyperlink',formattedLink($(this)), 'trackme', 1);
    });

    //Email hyperlinks
    $(document).delegate("a[href^='mailto:'],a[href^='Mailto:']", "click", function() {
       pageTracker._trackEvent('Email', emailAddress, 'Email', 1);
    });

    //PDF downloads  
    $(document).delegate("a[href$='.pdf'],a[href$='.PDF']", "click", function() {
         pageTracker._trackEvent('Download', formattedLink($(this)), 'PDF', 1);
    });

    //EXE downloads  
    $(document).delegate("a[href$='.exe'],a[href$='.EXE'],", "click", function() {
        pageTracker._trackEvent('Download', formattedLink($(this)), 'EXE', 1);
    });

 
     //MSI downloads
    $(document).delegate("a[href$='.msi'],a[href$='.MSI'", "click", function() {
       pageTracker._trackEvent('Download', formattedLink($(this)), 'EXE', 1);
    });


    //ZIP downloads 
    $(document).delegate("a[href$='.zip'],a[href$='.ZIP']", "click", function() {
       pageTracker._trackEvent('Download', formattedLink($(this)), 'Archive', 1);
    });
});

// Returns the href of a hyperlink ojbect in the correct format 
function formattedLink(myHyperlinkObject) {
    return myHyperlinkObject.get(0).href.replace('http://', '').replace('https://', '').replace(window.location.host, '').replace(window.location.host.replace('www.',''), '');
}
