//GA TRACKING v1.3 by www.blastam.com

if (typeof(bamGAID) != 'undefined') {

	var _bamGA = new Object();
	
	//settings
	_bamGA.accountMain = bamGAID;
	_bamGA.accountRollup = 'UA-306534-42';
	_bamGA.accountCareers = 'UA-25416077-1';
	_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]);
	
	if (typeof(bamGAUrchin) != 'undefined' && bamGAUrchin == true) {
		_gaq.push(['_setLocalRemoteServerMode']);
	}
	
	if (typeof(bamGAVPV) != 'undefined')
		_gaq.push(['_trackPageview', bamGAVPV]);
	else
		_gaq.push(['_trackPageview']);
		
	_gaq.push(['_trackPageLoadTime']);
	
	//rollup tracker
	_gaq.push(['rollup._setAccount', _bamGA.accountRollup]);
	_gaq.push(['rollup._setDomainName', _bamGA.cookieDomain]);
	_gaq.push(['rollup._setAllowLinker',true]);
	if (typeof(bamGAVPV) != 'undefined')
		_gaq.push(['rollup._trackPageview', bamGAVPV]);
	else
		_gaq.push(['rollup._trackPageview']);
	
	//handle tertiary tracker for www.bannerhealth.com/careers/*
	if (document.domain == 'www.bannerhealth.com' && document.location.pathname.match(/^\/careers\//i)) {
		_gaq.push(['careers._setAccount', _bamGA.accountCareers]);
		_gaq.push(['careers._setDomainName', _bamGA.cookieDomain]);
		_gaq.push(['careers._setAllowLinker', true]);
		if (typeof(bamGAVPV) != 'undefined')
			_gaq.push(['careers._trackPageview', bamGAVPV]);
		else
			_gaq.push(['careers._trackPageview']);
	}
	
	(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 = /\.(zip|exe|pdf|doc*|xls*|ppt*|mp3|slxb|pps*|vsd|vxd|txt|rar|wma|mov|avi|wmv|flv|wav)$/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]);
	                    _gaq.push(['rollup._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]);
	                    _gaq.push(['rollup._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]);
	                    _gaq.push(['rollup._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;
	                    }
	                });
	            }
	            //homepage elements on www.bannerhealth.com
	            else if (document.domain == 'www.bannerhealth.com' && document.location.pathname == '/') {
	            	jQuery(this).click(function() {
	            		_gaq.push(['_trackEvent', 'click-tracking', 'click-home', href, undefined, true]);
	            		_gaq.push(['rollup._trackEvent', 'click-tracking', 'click-home', href, undefined, true]);
	            		if (jQuery(this).attr('target') != undefined && jQuery(this).attr('target').toLowerCase() != '_blank') {
	                        setTimeout(function() { location.href = baseHref + href; }, 200);
	                        return false;
	                    }
	            	});
	            }
	            //track all page elements on any page that has bamGATrackPageClicks set to true
	            else if (typeof(bamGATrackPageClicks) != 'undefined' && bamGATrackPageClicks == true) {
	            	jQuery(this).click(function() {
	            		var thisPageTitle = document.title.trim().replace(/\s+/g, '-').replace(',','').toLowerCase();
	            		_gaq.push(['_trackEvent', 'click-tracking', 'click-' + thisPageTitle, href, undefined, true]);
	            		_gaq.push(['rollup._trackEvent', 'click-tracking', 'click-' + thisPageTitle, href, undefined, true]);
	            		if (jQuery(this).attr('target') != undefined && jQuery(this).attr('target').toLowerCase() != '_blank') {
	                        setTimeout(function() { location.href = baseHref + href; }, 200);
	                        return false;
	                    }
	            	});
	            }
	        }
	    });
	};
	
	_bamGA.trackEvent = function(gaEventCategory, gaEventAction, gaEventLabel) {
		_gaq.push(['_trackEvent', gaEventCategory, gaEventAction, gaEventLabel]);
		_gaq.push(['rollup._trackEvent', gaEventCategory, gaEventAction, gaEventLabel]);
	};
	
	_bamGA.setCustomVar = function(gaIndex, gaName, gaValue, gaScope) {
		_gaq.push(['_setCustomVar', gaIndex, gaName, gaValue, gaScope]);
		_gaq.push(['rollup._setCustomVar', gaIndex, gaName, gaValue, gaScope]);
	};
	
	_bamGA.trackForm = function(el, formDesc) {
		try {
			jQuery(el).find(':input').each(function(i) {
				if (jQuery(this).val() != null && jQuery(this).val().length > 0 && jQuery(this).attr('type') != 'hidden' && jQuery(this).attr('type') != 'button' && jQuery(this).attr('type') != 'submit') {
					if (jQuery(this).attr('type') == 'select-one') {
						_bamGA.trackEvent(formDesc, jQuery(this).attr('name'), jQuery('#' + jQuery(this).attr('id') + ' option:selected').text());
					}
					else {
						_bamGA.trackEvent(formDesc, jQuery(this).attr('name'), jQuery(this).val());
					}
				}
			});
			setTimeout(function() { jQuery(el).submit(); }, 500);
		}
		catch(e){}
	};
	
	_bamGA.getParameterByName = function(name)
	{
	  name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
	  var regexS = "[\\?&]" + name + "=([^&#]*)";
	  var regex = new RegExp(regexS);
	  var results = regex.exec(window.location.href);
	  if(results == null)
	    return undefined;
	  else
	    return decodeURIComponent(results[1].replace(/\+/g, " "));
	}
	
	//handle redirect parameter event tracking
	if (_bamGA.getParameterByName('rd') != undefined) {
		_gaq.push(['_trackEvent', 'redirect', _bamGA.getParameterByName('rd'), document.location.pathname, undefined, true]);
		_gaq.push(['rollup._trackEvent', 'redirect', _bamGA.getParameterByName('rd'), document.location.pathname, undefined, true]);
	}
	
	
	
	if (typeof jQuery != 'undefined') {
	    jQuery(document).ready(function($) {
	        _bamGA.trackOutbound();
	    });
	}

}

//END GA TRACKING
