var objGATrackLogic = {
	
	init: function() {
		
		var arrSegs = document.location.pathname.split("/");
		
		switch(arrSegs[1]) {
			
			// Character view
			case "kids":
				objGATrackLogic.trackCharacterView(arrSegs[2]);
			break;
			
			// DVD Page View
			case "the-big":
				objGATrackLogic.trackDVDView(arrSegs[2]);
			break;
				
			
		}
		
		var jQuerybody = jQuery("body");
		var jQuerypage = jQuery("#page");
		
		// Blog post or blog list page?
		if (jQuerybody.hasClass("category-blog") || jQuerypage.hasClass("in_category_blog")) {
			var strURLTitle = (!arrSegs[4]) ? 'Blog List Page' : arrSegs[4];
			objGATrackLogic.trackBlogView(strURLTitle);
		}
		
		// Video list or Video detail?
		if (jQuerybody.hasClass("category-videos") || jQuerypage.hasClass("in_category_videos")) {
			var strURLTitle = (!arrSegs[4]) ? 'Video List Page' : arrSegs[4];
			objGATrackLogic.trackVideoView(strURLTitle);
		}
		
		// 404 Page?
		if (jQuerybody.hasClass("error404")) {
			var strURL = "/not_found_404.html?page=" + document.location.pathname + document.location.search + "&from=" + document.referrer;
			objGATrackLogic.track404(strURL);
		}
		
		// JellyTelly Exit Link
		objGATrackLogic.trackJellyTellyExitLink();
		
		// Any link going to the store
		objGATrackLogic.trackPassToStore();
		
		// Hook the newsletter submit form
		objGATrackLogic.trackNewsletterSubmit();
		
		// Hook the blog's comment submit form
		objGATrackLogic.trackBlogCommentSubmit();
		
		// Track sociable links
		objGATrackLogic.trackSociableLinks();
		
		// Track download links
		objGATrackLogic.trackDownloadLinks();
		
	},
	
	trackCharacterView: function(strCharacterName) {
		
		if (strCharacterName) {
			
			objGATracker.setCustomVar(1, "Character", strCharacterName, 3);
			
		}
		
	},
	
	trackDVDView: function(strDVDTitle) {
		
		if (strDVDTitle) {
			
			objGATracker.setCustomVar(2, "Title", strDVDTitle, 3);
			
		}
		
		jQuery(".OoyalaVideoPlayer").live("click", function() { alert("help"); });
		
	},
	
	trackDownloadLinks: function() {
	
		jQuery("a").live("click", function() {
			
			var $link = jQuery(this);
			
			if ($link.attr("href").search(/download\.php/gi) !== -1) {
				
				$link.attr("target", "_blank");

				var strDownloadTitle = $link.attr("title");
				var $embeddedImage = $link.find("img");

				// If the link doesn't have a title, look for an image that does further down the DOM.
				if (!strDownloadTitle && $embeddedImage.length && $embeddedImage.attr("title").length) {
					strDownloadTitle = $embeddedImage.attr("title");
				}

				objGATracker.trackEvent("PDF", "Download", strDownloadTitle);
				
			}
			
			
			
		});
		
	},
	
	trackJellyTellyExitLink: function() {
		
		jQuery(".link-jellytelly").live("click", function() {
			
			objGATracker.trackEvent("Links", "Exit", "JellyTelly");
			
		});
		
	},
	
	trackPassToStore: function() {
		
		jQuery("a").live("click", function() {
			
			var strURL = this.href;
			
			if (strURL.indexOf("store.whatsinthebible.com") != -1) {
				
				objGATracker.trackEvent("Store", "Pass to Store");
				
			}
			
		});
		
	},
	
	trackNewsletterSubmit: function() {
		
		jQuery("#mc_signup_form").live("submit", function() {
			
			objGATracker.trackEvent("Newsletter", "Sign Up");
			
		});
		
	},
	
	trackBlogCommentSubmit: function() {
		
		jQuery("#comments").live("submit", function() {
			
			var arrSegs = document.location.pathname.split("/");
			var strURLTitle = arrSegs[4];
			
			objGATracker.trackEvent("Blog", "Comment", strURLTitle);
			
		});
		
	},
	
	trackBlogView: function(strURLTitle) {
		
		objGATracker.setCustomVar(3, "Blog Post", strURLTitle, 3);
		
	},
	
	trackVideoView: function(strURLTitle) {
		
		objGATracker.setCustomVar(2, "Title", strURLTitle, 3);
		
	},
	
	track404: function(strURI) {
		
		objGATracker.trackPageview(strURI);
		
	},
	
	trackSociableLinks: function() {
		
		jQuery(".sociable a").live("click", function() {
			
			var $link = jQuery(this);
			var strNetwork = $link.attr("title");
			var strAction = "Like";
			var strTitle = "";
			
			$link.attr("target", "_blank");
			
			switch(strNetwork.toLowerCase()) {
				
				case "digg":
					strAction = "Digg";
					break;
				
				case "sphinn":
					strAction = "Sphinn";
					break;
				
				case "del.icio.us":
					strAction = "bookmark";
					break;
				
				case "facebook":
					strAction = "like";
					break;
				
				case "mixx":
					strAction = "share";
					break;
				
				case "blogplay":
					strAction = "share";
					break;
				
				default:
					strAction = "unknown";
					break;
					
			}
			
			var jQuerydocTitle = jQuery("title");
			strTitle = jQuerydocTitle.html().replace(/what\'s in the bible/gi, "").replace("»", "");
			
			objGATracker.trackSocial(strNetwork, strAction, jQuery.trim(strTitle));
			
		});
		
	}
	
};
