//GA TRACKING v1.2 by www.blastam

if (document.location.hostname.match(/qa\.medicare\.gov/i))
	bamGAID = 'UA-15356370-23';
else if (document.location.hostname.match(/staging\.medicare\.gov/i))
	bamGAID = 'UA-15356370-22';
else if (document.location.hostname.match(/qa\.cms\.gov/i))
	bamGAID = 'UA-15356370-21';
else if (document.location.hostname.match(/medicare\.gov/i))
	bamGAID = 'UA-15356370-2';
else if (document.location.hostname.match(/cciio\.cms\.gov/i))
	bamGAID = 'UA-15356370-19';
else if (document.location.hostname.match(/cms\.gov/i))
	bamGAID = 'UA-15356370-3';
else if (document.location.hostname.match(/hhs\.gov/i))
	bamGAID = 'UA-15356370-9';
else if (document.location.hostname.match(/medicaid\.gov/i))
	bamGAID = 'UA-15356370-25';



if (typeof(bamGAID) != 'undefined') {

	var _bamGA = new Object();
	
	//settings
	_bamGA.accountMain = bamGAID;
	_bamGA.cookieDomain = '.' + document.domain.split('.').reverse()[1] + '.' + document.domain.split('.').reverse()[0];
	_bamGA.thisDomain = document.domain.split('.').reverse()[1] + '.' + document.domain.split('.').reverse()[0];

	var _gaq = _gaq || [];
	_gaq.push(['_setAccount', _bamGA.accountMain]);
	_gaq.push(['_setDomainName', _bamGA.cookieDomain]);
	_gaq.push(['_setAllowLinker', true]);
	_gaq.push(['_setAllowAnchor', true]);
	
	if (typeof(bamGAUrchin) != 'undefined' && bamGAUrchin == true) {
		_gaq.push(['_setLocalRemoteServerMode']);
	}
	
	if (typeof(bamGAVPV) != 'undefined')
		_gaq.push(['_trackPageview', bamGAVPV]);
	else
		_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);
	})();
	
	//outbound, cross-domain, & advanced tracking
	_bamGA.trackOutbound = function() {
		var filetypes = /\.(doc|eps|jpg|png|svg|xls|ppt|pdf|xls|zip|txt|vsd|vxd|js|css|rar|exe|wma|mov|avi|wmv|mp3)$/i;
	    var baseHref = '';
	    if (jQuery('base').attr('href') != undefined) {
	        baseHref = jQuery('base').attr('href');
	    }
	    jQuery('a').each(function() {
	        var href = jQuery(this).attr('href');
	        if (href != undefined && !href.match(/^javascript:/i)) {
	            //outbound
	            if (href.match(/^https?\:/i) && !href.match(_bamGA.thisDomain)) {
	                jQuery(this).click(function() {
	                    var extLink = href.replace(/^https?:\/\//i, '');
	                    _gaq.push(['_trackEvent', 'external', 'click', extLink]);
	                    if (jQuery(this).attr('target') != undefined && jQuery(this).attr('target').toLowerCase() != '_blank') {
	                        setTimeout(function() { location.href = href; }, 200);
	                        return false;
	                    }
	                });
	            }
	            //mailto
	            else if (href.match(/^mailto\:/i)) {
	                jQuery(this).click(function() {
	                    var mailLink = href.replace(/^mailto\:/i, '');
	                    _gaq.push(['_trackEvent', 'email', 'click', mailLink]);
	                });
	            }
	            //file downloads
	            else if (href.match(filetypes)) {
	                jQuery(this).click(function() {
	                    var extension = (/[.]/.exec(href)) ? /[^.]+$/.exec(href) : undefined;
	                    var filePath = href;
	                    _gaq.push(['_trackEvent', '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;
	                    }
	                });
	            }
	        }
	    });
	};
	
	if (typeof jQuery != 'undefined') {
	    jQuery(document).ready(function($) {
	        _bamGA.trackOutbound();
	    });
	}

}

//END GA TRACKING
