/*******************************************************************
 *
 * To use this tracking code, first replace the Google and 
 * Doubleclick credentials at the top of this file. This determines
 * the GA and DblClick accounts which receive the usage statistics.
 * 
 * The next step is to fill in the init() sections for both GA and 
 * DoubleClick. This is where you will wire up the events which 
 * result in a tag firing. For DoubleClick you will have two blocks, 
 * one for Floodlight (page-load) tags and one for the Spotlight 
 * (event-triggered) tags.
 * 
 *******************************************************************/
var _gaq = _gaq || [];
//_gaq.push(['_setAccount', window.location.host.match(/sop/i) ? 'UA-1231141-4' : 'UA-1231141-4']); 
_gaq.push(['_setAccount', 'UA-1231141-4']); 
// Manually to the page loads
//_gaq.push(['_trackPageview']);

// Note that the URLs for doubleclick are hardcoded as http, not https. 
// If you're deploying to a site served from an SSL context, you will need to modify the URLs below to use https.
// doubleclick/Digitas Health tracking
// example url: http://fls.doubleclick.net/activityi;src=3012733;type=voi193;cat=vom317;ord=1;num=7329405330720.819?
var dblClickSrc = '3012733';
var dblClickGroup = '2011sop';
	
var tr = {
	init:function() {
		this.google.init();
		this.dblClick.init();
	},

	dblClick:{
		init:function(){
			/* floodlights - see jquery.serialscroll.colorbox.init
			var thisUrl = new String(document.location.href);
			if (thisUrl.match('what-is-pertussis.cfm')) {
				this.floodlight('whati091');
			}  
			if (thisUrl.match('why-get-vaccinated.cfm')) {
				this.floodlight('whyge515');
			}  
			if (thisUrl.match('talk-to-your-doctor-today.cfm')) {
				this.floodlight('talkt102');
			}  
			if (thisUrl.match('babies-need-protection-too.cfm')) {
				this.floodlight('babie807');
			}	*/	
			// spotlights -- NOTE: not ALL spotlight calls can be found in this file
			//$('#linkToDown[href*="Ask your childs school nurse.pdf"]').click(function(){
				//tr.dblClick.spotlight('downl899);
			//});
			// index page			
			/* 
			$('.transcript-racer').click(function(){				
				tr.dblClick.spotlight('what-079');
			});	*/	
				
			$('#rtba').click(function(){				
				tr.dblClick.spotlight('rtbal298');
			});	
			// what 
			$('#pertussis-is-a-fatal-cough p.cta').click(function(){	
				if ($('#pertussis-is-a-fatal-cough').height() < 300 ) {
					tr.dblClick.spotlight('what-854');
				} else {
					
				}			
			});
			$('#whooping-cough-symptoms p.cta').click(function(){				
				if ($('#whooping-cough-symptoms').height() < 300 ) {
					tr.dblClick.spotlight('what-758');
				} else {
				
				}
			});
			$('#families-spread-it p.cta').click(function(){	
				if ($('#families-spread-it').width() < 200 ) {
					tr.dblClick.spotlight('what-532');
				} else {
				
				}			
			});
			$('#a-rising-threat-of-pertussis p.cta').click(function(){				
				tr.dblClick.spotlight('what-114');
			});
			$('#share-your-story p.cta').click(function(){				
				tr.dblClick.spotlight('what-549');
			});
			$('.transcript-mother').click(function(){				
				tr.dblClick.spotlight('what-079');
			});			
			// why get vaccinate
			$('#adult-immunity-wears-off p.cta').click(function(){				
				if ($('#adult-immunity-wears-off').height() < 300 ) {
					tr.dblClick.spotlight('why-a784');
				} else {
				
				}
			});
			$('#infants-are-at-risk-for-pertussis p.before').click(function(){				
				tr.dblClick.spotlight('why-i944');
			});
			$('#football-team-passes-around-pertussis p.cta').click(function(){				
				tr.dblClick.spotlight('why-f752');
			});
			$('.transcript-family').click(function(){				
				tr.dblClick.spotlight('whyge919');
			});
			// doctor page
			$('#pertussis-is-preventable p.cta').click(function(){				
				if ($('#pertussis-is-preventable').width() < 500 ) {
					tr.dblClick.spotlight('talk-856');
				} else {
				
				}
			});
			$('.print_pdf').click(function(){
				tr.dblClick.spotlight('talk-868');
			});	
			$('.transcript-doctor').click(function(){			
				tr.dblClick.spotlight('talk-160');
			});	
			// babies page
			$('#babies-are-at-risk-for-pertussis p.cta').click(function(){				
				if ($('#babies-are-at-risk-for-pertussis').width() < 500 ) {
					tr.dblClick.spotlight('bnpt-004');
				} else {
				
				}
			});
			$('#find-out-more-about-childhood-vaccines p.cta').click(function(){				
				tr.dblClick.spotlight('bnpt-079');
			});
			$('#follow-the-infant-immunization-schedule #cta-follow').click(function(){			
				if ($('#follow-the-infant-immunization-schedule').height() < 300 ) {
					tr.dblClick.spotlight('bnpt-401');
				} else {
				
				}
			});
			$('#prevention-is-the-best-defense p.cta').click(function(){			
				if ($('#prevention-is-the-best-defense').height() < 200 ) {
					tr.dblClick.spotlight('bnpt-853');
				} else {
					
				}
			});			
			$('#follow-the-infant-immunization-schedule #cta').click(function(){			
				if ($('#follow-the-infant-immunization-schedule').height() < 300 ) {
					tr.dblClick.spotlight('bnpt-401');
				} else {

				}
			});
			$('#follow-the-infant-immunization-schedule .link-arrow').click(function(){				
				tr.dblClick.spotlight('bnpt-255');
			});	
			$('#adults-need-to-get-vaccinated-too .ext').click(function(){				
				tr.dblClick.spotlight('bnpt-801');
			});
			
			//next navigation 
			$('img.start').click(function(){	
				tr.dblClick.spotlight('whati091');
			});			
			//next navigation 
			$('#next-next').click(function(){	
				if ($('#navigation-section-2').hasClass('active')) {
					tr.dblClick.spotlight('whyge045');
				}
				if ($('#navigation-section-3').hasClass('active')) {
					tr.dblClick.spotlight('talkt102');
				}
				if ($('#navigation-section-4').hasClass('active')) {
					tr.dblClick.spotlight('babie807');
				}
			});
			//back navigation			
			$('#back-back').click(function(){
				if ($('#navigation-section-1').hasClass('active')) {
					tr.dblClick.spotlight('whati091');
				}
				if ($('#navigation-section-2').hasClass('active')) {
					tr.dblClick.spotlight('whyge045');
				}
				if ($('#navigation-section-3').hasClass('active')) {
					tr.dblClick.spotlight('talkt102');
				}
			});
			//restart
			$('#restart-next').click(function(){
				tr.dblClick.spotlight('whati091');
			});	
			//top of the page
			$('#doctor-locator').click(function(){
				tr.dblClick.spotlight('finda332');
			});					
			$('#icon-fb').click(function(){
				tr.dblClick.spotlight('socia991');
			});				
			$('#icon-twitter').click(function(){
				tr.dblClick.spotlight('socia637');
			});
			$('#icon-email').click(function(){
				tr.dblClick.spotlight('socia861');
			});			
			$('#section-fblike').click(function(){
				tr.dblClick.spotlight('socia629');
			});			
			$('#share').submit(function(){
				tr.dblClick.spotlight('what-313');
			});
					
		},
		floodlight:function(actTag) {
			var axel = Math.random() + "";
			var a = axel * 10000000000000;
			$('body').append('<iframe src="http://fls.doubleclick.net/activityi;src='+dblClickSrc+';type='+dblClickGroup+';cat='+actTag+';ord=1;num=' + a + '?" width="1" height="1" frameborder="0" style="display:none"></iframe>');
		},
		spotlight:function(category) {
			var axel = Math.random() + "";
			var a = axel * 1000000000000000000;

			var doPing = new Image();
			// the URL below is a spotlight tag for page
			doPing.src = 'http://ad.doubleclick.net/activity;src=' + dblClickSrc + ';type=' + dblClickGroup + ';cat=' + category + ';ord=1;num=' + a + '?';
			doPing.onload = function() { 
				// $.noop() does nothing, but the presence of a 
				// function call here will ensure the dblclick tracking
				// image is downloaded everytime
				$.noop(); 
				
				// substitute for noop() which is not available in jquery 1.2.6
				// var ii = 1+1; 
			};
			//ui.debug('returning followLink with value: ' + followLink);
			//return followLink;
		}
	},
	
	google:{
		init: function() {
			try {
				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);
			} catch (ee) {
				; //do nothing
			}
			// example GA event tag
			$('.abc').click(function(){
				tr.google.gtag('Clicks on Submit', 'Clicks on Submit');
			});
			
			// Bottom navigation click tagging
			$('#navigation-section-1, #navigation-section-2, #navigation-section-3, #navigation-section-4').live("click", function(){
				var sectionNum = $(this).attr("id").substring($(this).attr("id").length -1)   // get last digit from ID

				var eventName, kpi;
				switch(sectionNum)	{
					case 1:
						eventName = "SOP_What_is_pertussis";
						kpi = "What is pertussis";
						break;
					case 2:
						eventName = "SOP_Why_get_vaccinated";
						kpi = "";
						break;
					case 3:
						eventName = "SOP_Talk_to_your_doctor";
						kpi = "Talk to your doctor";
						break;
					case 4:
						eventName = "SOP_Babies_need_protection_too";
						kpi = "Babies need protection too!";
						break;
				}
				tr.google.gtag(eventName, kpi);	
			});
			
			$('#icon-fb').click(function(){
				tr.google.gtag('SOP_Social_Facebook', 'Facebook');
			});
			$('#share-twitter').click(function(){
				tr.google.gtag('SOP_Social_Twitter', 'Twitter');
			});
			$('#sendtoafriend').click(function(){
				tr.google.gtag('SOP_Social_Email', 'Email');
			});
			$('#LikePluginPagelet').click(function(){
				tr.google.gtag('SOP_Social_Facebook_Likes', 'Facebook Likes');
			});
			// share your story
			$('#my-story').click(function(){
				tr.google.gtag('SOP_Social_Share_Your_Story', 'Share Your Story');
			});
			// Print PDF
			$('.print_pdf a').click(function(){
				tr.google.gtag('SOP_Print_PDF', 'Print PDF');
			});
			//  Panel links on home page
			$('#whatispertussis-link').click(function(){
				tr.google.gtag('SOP_Panel_1_What_is_pertussis', 'What is pertussis');
			});
			$('#whygetvaccines-link').click(function(){
				tr.google.gtag('SOP_Panel_2__Why_get_vaccines', 'Why get vaccines');
			});
			// Terrifying sounds on home page
			$('#terrifying-sound').click(function(){
				tr.google.gtag('SOP_Video_Terrifying_Sound_Starts', 'Terrifying sounds (audio)');
			});
			
			//tracking next button clicks
			$('img.next, img.previous').click(function(){
				// 
				if ($(location).attr('href').indexOf('what-is-pertussis.cfm') != -1)	{
					tr.google.gtag('SOP_What_is_pertussis_arrow', 'What is pertussis');
				} else if ($(location).attr('href').indexOf('why-get-vaccinated.cfm') != -1) {
					tr.google.gtag('SOP_Why_get_vaccinated_arrow', 'Why get vaccinated');
				} else if ($(location).attr('href').indexOf('talk-to-your-doctor-today.cfm') != -1) {
					tr.google.gtag('SOP_Talk_to_your_doctor_arrow', 'Talk to your doctor');
				} else if ($(location).attr('href').indexOf('babies-need-protection-too.cfm') != -1) {
					tr.google.gtag('SOP_Babies_need_protection_too_arrow', 'Babies need protection too!');
				} else {
					// Home page
				}
			});
			
			/* video tracking based in xml */
			audioPlay = function() 
			{
				tr.google.gtag('SOP_Video_Terrifying_Sound', 'Terrifying Sound (Audio)');
			}
		},
		gtag: function(cat, act, lbl, val) {
            // val MUST be an integer, no decimal point
            // if you pass anything else the call will NOT work
			_gaq.push(['_trackEvent', cat, act, lbl, val]);
		}
	}
}

var ui = {
	debug:function(str){
    if (typeof (console) != "undefined") {
        console.log(message);
    }
	}
}


$(window).bind('load', function() { 
	tr.init(); 
	// pageLoad tracking
	//_gaq.push(['_trackPageview']);
});
