var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-6229460-1']);
_gaq.push(['_trackPageview']);

// 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 = 'foi';

var tr = {
	init:function() {
		this.google();
		this.dblClick.init();
	},

	dblClick:{
		init:function(){
		// floodlights -- NOTE: most pages on the nurses-site are NOT tagged with floodlight
		var thisUrl = new String(document.location.href);
		if (thisUrl.match('index.html$')) {
		this.floodlight('foi');
		}
		/* spotlights -- NOTE: not ALL spotlight calls can be found in this file*/
		$('a[href*="Grassroots Tool Kit.zip"]').click(function(){
			//alert('download grassroots');
			tr.dblClick.spotlight('','grass911',true);
		});
		$('a[href*="http://www.lungusa.org/lung-disease/influenza/flu-clinic-locator/"]').click(function(){
			//alert('vacinne finder');
			tr.dblClick.spotlight('','fluva569',true);
		});
	},
	
	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(href, category, followLink) {
		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: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
		}
		$('a[href*="flu-clinic-locator"]').click(function(){
			_gaq.push(['_trackEvent','Click_Flu_Vaccine_Finder','Find a Flu Shot']);
		});
		$('a.Tell').click(function(){
			_gaq.push(['_trackEvent','Click_Tell_Someone','Tell Someone']);
		});
		$('form#mailfriendForm').submit(function(){
			if (mailFriendFormIsValid()) {
				// this one will need to change so it only fires after validation is passed
				_gaq.push(['_trackEvent','Click_Tell_Someone','Tell Someone Submit']);
			}
		});
		$('a.Camp').click(function(){
			_gaq.push(['_trackEvent','Click_Grassroot_Campaign','Click on the Grassroot tab']);
		});
		// grassroots downloadables
		// public ed tab
		$('a[href*="MKT19914-1-1R Consumer Brochure.pdf"]').click(function(){
			_gaq.push(['_trackEvent','Click_Grassroot_Materials','MKT19914-1-1R Consumer Brochure.pdf']);
		});
		$('a[href*="MKT19912-1-1R Myths & Facts.pdf"]').click(function(){
			_gaq.push(['_trackEvent','Click_Grassroot_Materials','MKT19912-1-1R Myths & Facts.pdf']);
		});
		$('a[href*="MKT19913-1-1R Vaccination Recommendations.pdf"]').click(function(){
			_gaq.push(['_trackEvent','Click_Grassroot_Materials','MKT19913-1-1R Vaccination Recommendations.pdf']);
		});
		$('a[href*="MKT19915-1-1R Poster-Flyer.pdf"]').click(function(){
			_gaq.push(['_trackEvent','Click_Grassroot_Materials','MKT19915-1-1R Poster-Flyer.pdf']);
		});
		$('a[href*="MKT19927 FOI Presentation.ppt"]').click(function(){
			_gaq.push(['_trackEvent','Click_Grassroot_Materials','MKT19927 FOI Presentation.ppt']);
		});
		$('a[href*="Customizable Sticker With Directions.zip"]').click(function(){
			_gaq.push(['_trackEvent','Click_Grassroot_Materials','Customizable Sticker With Directions.zip']);
		});
		// communications materials tab
		$('a[href*="MKT19918-1R Article Template FOI Program.doc"]').click(function(){
			_gaq.push(['_trackEvent','Click_Grassroot_Materials','MKT19918-1R Article Template FOI Program.doc']);
		});
		$('a[href*="MKT19920-1R Article Template Duration of the Flu Season.doc"]').click(function(){
			_gaq.push(['_trackEvent','Click_Grassroot_Materials','MKT19920-1R Article Template Duration of the Flu Season.doc']);
		});
		$('a[href*="MKT19919-1R Article Template Make an Flu Vaccine Appt.doc"]').click(function(){
			_gaq.push(['_trackEvent','Click_Grassroot_Materials','MKT19919-1R Article Template Make an Flu Vaccine Appt.doc']);
		});
		// media and promotional
		$('a[href*="MKT19921-1-1R Faces of Influenza Backgrounder.pdf"]').click(function(){
			_gaq.push(['_trackEvent','Click_Grassroot_Materials','MKT19921-1-1R Faces of Influenza Backgrounder.pdf']);
		});
		$('a[href*="MKT19922-1R Template Letter-to-the-Editor.doc"]').click(function(){
			_gaq.push(['_trackEvent','Click_Grassroot_Materials','MKT19922-1R Template Letter-to-the-Editor.doc']);
		});
		$('a[href*="MKT19923-1R Template Press Release 2010-2011 Season Kick Off.doc"]').click(function(){
			_gaq.push(['_trackEvent','Click_Grassroot_Materials','MKT19923-1R Template Press Release 2010-2011 Season Kick Off.doc']);
		});
		$('a[href*="MKT19924-1R Template Media Alert - Clinic-Faces Event.doc"]').click(function(){
			_gaq.push(['_trackEvent','Click_Grassroot_Materials','MKT19924-1R Template Media Alert - Clinic-Faces Event.doc']);
		});
		$('a[href*="MKT19925-2-1R Template Ad Quarter Page.pdf"]').click(function(){
			_gaq.push(['_trackEvent','Click_Grassroot_Materials','MKT19925-2-1R Template Ad Quarter Page.pdf']);
		});
		$('a[href*="MKT19926-1R Template Regional Ad Quarter Page.pdf"]').click(function(){
			_gaq.push(['_trackEvent','Click_Grassroot_Materials','MKT19926-1R Template Regional Ad Quarter Page.pdf']);
		});
	}
}

function gaTag(cat,act,label) {
	try {
		_gaq.push(['_trackEvent',cat,act,label]);
	} catch (err) {
		; // do nothing, for now
	}
}

var ui = {
	debug:function(message){
			if (typeof (console) != "undefined") {
					console.log(message);
			}
	}
}

$(window).bind("load", function() { tr.init(); });
