// activate google analitics with jquery.google-analytics.js plugin
// edit the Google Tracking number
$.trackPage('UA-1625565-1');

$(document).ready(function() {
												 				 
//track mailto and downloads with Google Analytics
	$('a').each(function() { //loop though each anchor element
		var href = $(this).attr('href');
		var filetypes = /\.(zip|exe|pdf|doc*|xls*|ppt*|mp3)$/i;
		
		//check for links starting with mailto:
		if (href.match(/^mailto\:/i)){
			$(this).click(function() {
				var mailLink = href.replace(/^mailto\:/i, '');
				$.trackEvent("Email", "Click", mailLink);
			});
		}
		//check for links with file extension that match the filetypes regular expression:
		else if (href.match(filetypes)){
			$(this).click(function() {
				var extension = (/[.]/.exec(href)) ? /[^.]+$/.exec(href) : undefined;
				var filePath = href.replace(/^https?\:\/\/(www.)cornerstonelodi\.com\//i, '');
				$.trackEvent("Download", "Click - " + extension, filePath);
			});
		}
	});
	
	//Google Analytics for events
	$("#audio a, #new_photos a, #visitors a").click(function() { //Home Page audio sermons button
		var title = $(this).attr("title");
		$.trackEvent("Home Page", "Click", title);
	});
	$("#audio_downloads a").click(function() { //Audio sermons listen
		var title = $(this).text();
		$.trackEvent("Audio", "download", title);
	});
});
