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

$(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
	$(".video .video-link").click(function() { //Guitar Lesson Videos
		var title = $(this).text();
    if (title == "") {
      title = $(this).children().attr("alt");
    }
    $.trackEvent("Lesson Video", "Click", title);
	});
  $("#latest-video .video-link").click(function() { //Guitar Lesson Videos
		var title = $(this).text();
    if (title == "") {
      title = $(this).children().attr("alt");
    }
    $.trackEvent("Featured Video", "Click", title);
	});

});
