/*******************************************************************
 *
 * 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(/vaccines/i) ? 'UA-442740-2' : 'UA-442740-2']); 
_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 = 'vacci440';
	
	
 var tr = {
	init:function() {
		this.google.init();
		this.dblClick.init();
	},

	dblClick:{
		init:function(){
			// floodlights
			var thisUrl = new String(document.location.href);
			if (thisUrl.match('vaccines-infants-young-children.cfm$')) {
				this.floodlight('infan096');
			} 
			if (thisUrl.match('vaccines-adults.cfm$')) {
				this.floodlight('adult121');
			} 
			if (thisUrl.match('vaccines-seniors.cfm$')) {
				this.floodlight('senio362');
			} 
			if (thisUrl.match('about-vaccines.cfm$')) {
				this.floodlight('about779');
			}
			if (thisUrl.match('index.cfm$')) {
				this.floodlight('vacci670');
			}
			if (thisUrl.match('why-vaccinate.cfm$')) {
				this.floodlight('about881');
			}
			if (thisUrl.match('vaccine-safety.cfm$')) {
				this.floodlight('about668');
			}
			if (thisUrl.match('measles-history.cfm$')) {
				this.floodlight('about235');
			}
			if (thisUrl.match('vaccine-questions-answers.cfm$')) {
				this.floodlight('about011');
			}
			if (thisUrl.match('protect-your-family.cfm$')) {
				this.floodlight('prote288');
			}
			if (thisUrl.match('vaccinations.cfm$')) {
				this.floodlight('prote935');
			}
			if (thisUrl.match('about-immyounity.cfm$')) {
				this.floodlight('about789');
			}
			if (thisUrl.match('educate-others.cfm$')) {
				this.floodlight('educa690');
			}
			if (thisUrl.match('vaccines-pre-teens.cfm$')) {
				this.floodlight('vacci128');
			}
			if (thisUrl.match('influenza-vaccine.cfm$')) {
				this.floodlight('fluva496');
			}
			if (thisUrl.match('pertussis-whooping-cough-vaccine.cfm$')) {
				this.floodlight('pertu188');
			}
			if (thisUrl.match('hepatitis-b-vaccine.cfm$')) {
				this.floodlight('hepat627');
			}
			if (thisUrl.match('polio-vaccine.cfm$')) {
				this.floodlight('polio549');
			}
			if (thisUrl.match('hpv-human-papillomavirus-vaccine.cfm$')) {
				this.floodlight('hpvva303');
			}
			// 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);
			//});
		},
		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
			/* */
			
			$('a').has('img[src*="1-1_infographic_01_thumb.gif"]').click(function(){
				tr.google.gtag('Clicked_Infographic_1_odds', 'infographic/fact card consumption');
			});
			$('a').has('img[src*="1-1_infographic_02_thumb.gif"]').click(function(){
				tr.google.gtag('Clicked_Infographic_2_vaccine_works', 'infographic/fact card consumption');
			});
			$('a').has('img[src*="1-1_infographic_03_thumb.gif"]').click(function(){
				tr.google.gtag('Clicked_Infographic_3_measles_issue', 'infographic/fact card consumption');
			});
			$('a').has('img[src*="1-1_infographic_04_thumb.gif"]').click(function(){
				tr.google.gtag('Clicked_Infographic_4_health_achievements', 'infographic/fact card consumption');
			});
			$('a').has('img[src*="1-1_infographic_05_thumb.gif"]').click(function(){
				tr.google.gtag('Clicked_Infographic_5_vaccines_undercontol', 'infographic/fact card consumption');
			});
			$('a').has('img[src*="1-1_infographic_06_thumb.gif"]').click(function(){
				tr.google.gtag('Clicked_Infographic_6_parents_think', 'infographic/fact card consumption');
			});
			$('a').has('img[src*="1-1_infographic_07_thumb.gif"]').click(function(){
				tr.google.gtag('Clicked_Infographic_7_polio_past', 'infographic/fact card consumption');
			});
			$('a').has('img[src*="1-1_infographic_08_thumb.gif"]').click(function(){
				tr.google.gtag('Clicked_Infographic_8_vaccinces_cancer', 'infographic/fact card consumption');
			});
			$('a').has('img[src*="1-1_infographic_09_thumb.gif"]').click(function(){
				tr.google.gtag('Clicked_Infographic_9_pertussis_sense', 'infographic/fact card consumption');
			});
			$('a').has('img[src*="1-1_infographic_10_thumb.gif"]').click(function(){
				tr.google.gtag('Clicked_Infographic_10_vaccines_lifesavers', 'infographic/fact card consumption');
			});
			$('a').has('img[src*="1-1_infographic_11_thumb.gif"]').click(function(){
				tr.google.gtag('Clicked_Infographic_11_children_hepb', 'infographic/fact card consumption');
			});
			$('a').has('img[src*="1-1_infographic_12_thumb.gif"]').click(function(){
				tr.google.gtag('Clicked_Infographic_12_flu_fact', 'infographic/fact card consumption');
			});
			$('a.connect_widget_like_button clearfix like_button_no_like').click(function(){
				tr.google.gtag('Click_Facebook_Likes', 'advocate conversation share');
			});
			// email click tracking moved to individual email form page
			// twitter tracking see ga social tracking
		},
		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(); });
