// JavaScript Document
	//console.log('script found');
if (typeof jQuery != 'undefined') {
    jQuery(document).ready(function($) {
        var sitecoremedia = /~\/media/i;
        var filetypes = /\.(zip|exe|pdf|doc*|xls*|ppt*|mp3|ashx)$/i;
        var baseHref = '';
        if (jQuery('base').attr('href') != undefined)
            baseHref = jQuery('base').attr('href');

        jQuery('a').each(function() {
            var href = jQuery(this).attr('href');
            var id = jQuery(this).attr('id');
            // External clicks
            if (href && (href.match(/^https?\:/i)) && (!href.match(document.domain))) {
                jQuery(this).click(function() {
                    var extLink = href.replace(/^https?\:\/\//i, '');
                    ga('send', 'event', 'External', 'Click', extLink);
                    if (jQuery(this).attr('target') == undefined || jQuery(this).attr('target').toLowerCase() != '_blank') {
                        setTimeout(function() { location.href = href; }, 200);
                        return false;
                    }
                });
            }
            // mailto clicks
            else if (href && href.match(/^mailto\:/i)) {
                jQuery(this).click(function() {
                    var mailLink = href.replace(/^mailto\:/i, '');
					ga('send', 'event', 'Email', 'Click', mailLink);
                });
            }
            // file clicks
            else if (href && (href.match(filetypes) || href.match(sitecoremedia))) {
                jQuery(this).click(function() {
                    var extension = (/[.]/.exec(href)) ? /[^.]+$/.exec(href) : undefined;
                    var filePath = href;
					ga('send', 'event', 'Download', 'Click-' + extension, filePath);
                    if (jQuery(this).attr('target') == undefined || jQuery(this).attr('target').toLowerCase() != '_blank') {
                        setTimeout(function() { location.href = baseHref + href; }, 200);
                        return false;
                    }
                });
            }
            // internal clicks with ids
            if (href && id && href !== "#") {
                jQuery(this).click(function() {
					ga('send', 'event', 'Internal-With-Id', 'Click', id);
                    if (jQuery(this).attr('target') == undefined || jQuery(this).attr('target').toLowerCase() != '_blank') {
                        setTimeout(function() { location.href = href; }, 200);
                        return false;
                    }
                });
            }
        });
    });
}