﻿$(document).ready(function() {        
    
    $('a[href^="http://"], a[href$=".pdf"]').each(function(){
        var path = $(this).attr("href");
        
        if((path.indexOf("http://www.pfaff.com/") != 0) && (path.indexOf("http://pfaff.com/") != 0)) {
            var filename = path.substr(path.lastIndexOf("/")+1,path.length);
            var filesuffix = filename.substr(filename.lastIndexOf(".")+1,filename.length);
            // set up GA vars, (assume pdf)
            var eventCategory = "Download";
            var eventAction = "Pdf";
            var eventLabel = path;
            if(filesuffix != "pdf") {
                eventCategory = "External Link";
                eventAction = "Link";
            }
            
            if($(this).attr('onclick') === undefined) {
                $(this).attr({
                    title:filename,
                    onclick: "_gaq.push([\'_trackEvent\', '"+eventCategory+"', '"+eventAction+"', '"+path+"']);"
                });
            }
        }
    });
});
