/**
 * AKQA Doubleclick Floodlight Tags
 * Creates Doubleclick Floodlight tags for page landings and button clicks.
 * Landing events are created based on the path. Click events are created
 * based on the element having a fls-tag class and switched on the ID.
 * These tags were added in September 2011.
 */
$(document).ready(function() {

	//Flag to tell if we need debugging. This looks for the URL of the page
	//containing the main domain.
	var flsDebug = ($(location).attr('host').indexOf('www.clorox.com') == -1 && typeof(console) != 'undefined');

	/**
	 * Function that implements the tag.
	 */
	function fireFlsTag(flsSrc, flsType, flsCat) {
		var axel = Math.random() + "";
		var a = axel * 10000000000000;
		$('body').append(
			'<iframe src="https://fls.doubleclick.net/' + 
			'activityi' + 
			';src=' + flsSrc + 
			';type=' + flsType +
			';cat=' + flsCat +
			';ord=' + a + '?' + 
			'" width="1" height="1" frameborder="0" ' + 
			'style="display:none"></iframe>');

		//This will fire off only on a non-production site. Use it to
		//check that tags are firing.
		if(flsDebug) { 
			console.log('QA FLS ' + flsSrc + ' ' + flsType + ' ' + flsCat);
		}
	}

	/**
	 * Tags that fire on landing
	 * 
	 */
	$('body').each(function() {
		//For debugging only. Should not do anything in production.
		if (flsDebug) { 
			console.log('Body ID ' + this.id + ' ' + $(location).attr('pathname'));
		}
		switch($(location).attr('pathname')) {
			case '/':
				fireFlsTag('3340030', 'homep453', 'cloro216');
				break;
			case '/products/':
				fireFlsTag('3340030', 'produ035', 'cloro636');
				break;
			case '/special-offers/':
				fireFlsTag('3340030', 'offer652', 'cloro982');
				break;
			case '/special-offers/coupons/':
				fireFlsTag('3340030', 'offer652', 'cloro577');
				break;
			case '/special-offers/guides/':
				fireFlsTag('3340030', 'offer652', 'cloro770');
				break;
			case '/register/':
				fireFlsTag('3340030', 'regis377', 'cloro797');
				break;
			case '/clorox-cleaning-and-laundry-advisor/':
				fireFlsTag('3340030', 'gener100', 'cloro749');
				break;
			case '/clorox-cleaning-and-laundry-advisor/healthier-home-and-family/':
				fireFlsTag('3334188', 'advisor', 'cloro855');
				break;
			case '/clorox-cleaning-and-laundry-advisor/cleaning-advisor/surprising-uses-for-bleach/':
				fireFlsTag('3340030', 'gener100', 'cloro466');
				break;
			case '/blogs/':
				fireFlsTag('3340030', 'gener100', 'cloro355');
				break;
			case '/our-commitment/':
				fireFlsTag('3340030', 'gener100', 'cloro258');
				break;
			case '/classrooms/':
				fireFlsTag('3340030', 'gener100', 'cloro710');
				break;
			case '/blogs/mom-moments/':
				fireFlsTag('3340030', 'blogs523', 'cloro428');
				break;
			case '/blogs/dr-laundry/':
				fireFlsTag('3340030', 'blogs523', 'cloro176');
				break;
			case '/cleaning-games/':
				fireFlsTag('3340030', 'games259', 'cloro349');
				break;
			case '/cleaning-games/disinfector-protector-cleaning-game/':
				fireFlsTag('3340030', 'games259', 'cloro048');
				break;
			case '/cleaning-games/stacks-cleaning-game/':
				fireFlsTag('3340030', 'games259', 'cloro832');
				break;
			case '/products/clorox-regular-bleach/bleach-it-away/':
				fireFlsTag('3340030', 'produ035', 'cloro319');
				break;
			case '/products/clorox-regular-bleach/':
				fireFlsTag('3340030', 'produ035', 'uzxrk899');
				break;
			case '/products/clorox-scented-bleach/':
				fireFlsTag('3340030', 'produ035', 'cloro456');
				break;
			case '/products/clorox2/':
				fireFlsTag('3340030', 'produ035', 'cloro054');
				break;
			case '/products/clorox2-stain-fighter-pen-and-spray/':
				fireFlsTag('3340030', 'produ035', 'cloro675');
				break;
			case '/products/clorox-disinfecting-wipes/':
				fireFlsTag('3340030', 'produ035', 'cloro329');
				break;
			case '/products/clorox-clean-up-cleaner/':
				fireFlsTag('3340030', 'produ035', 'cloro934');
				break;
			case '/products/clorox-toilet-bowl-cleaner-with-bleach/':
				fireFlsTag('3340030', 'produ035', 'cloro278');
				break;
			case '/products/clorox-automatic-toilet-bowl-cleaner/':
				fireFlsTag('3340030', 'produ035', 'cloro322');
				break;
			case '/products/clorox-toilet-wand-system/':
				fireFlsTag('3340030', 'produ035', 'cloro890');
				break;
			case '/products/clorox-splashless-bleach/':
				fireFlsTag('3340030', 'produ035', 'cloro458');
				break;
			case '/products/clorox-ultimate-care-bleach/':
				fireFlsTag('3340030', 'produ035', 'cloro984');
				break;
			case '/products/clorox-outdoor-bleach-cleaner/':
				fireFlsTag('3340030', 'produ035', 'cloro926');
				break;
			case '/products/clorox-high-efficiency-bleach/':
				fireFlsTag('3340030', 'produ035', 'cloro419');
				break;
			case '/products/clorox-washing-machine-cleaner/':
				fireFlsTag('3340030', 'produ035', 'cloro372');
				break;
			case '/products/clorox-toilet-bowl-cleaner-clinging-bleach-gel/':
				fireFlsTag('3340030', 'produ035', 'cloro560');
				break;
			case '/products/clorox-bleach-pen/':
				fireFlsTag('3340030', 'produ035', 'cloro200');
				break;
			case '/products/clorox-oxi-magic/':
				fireFlsTag('3340030', 'produ035', 'dpflj115');
				break;
			case '/products/clorox-disinfecting-kitchen-cleaner/':
				fireFlsTag('3340030', 'produ035', 'cloro750');
				break;
			case '/products/clorox-readymop-mopping-system/':
				fireFlsTag('3340030', 'produ035', 'cloro774');
				break;
			case '/products/clorox-anywhere-hard-surface-daily-sanitizing-spray/':
				fireFlsTag('3340030', 'produ035', 'cloro533');
				break;
			case '/products/clorox-disinfecting-bathroom-cleaner/':
				fireFlsTag('3340030', 'produ035', 'cloro139');
				break;
			case '/products/clorox-bleach-foamer/':
				fireFlsTag('3340030', 'produ035', 'cloro441');
				break;
			case '/products/clorox-clorogel/':
				fireFlsTag('3340030', 'produ035', 'cloro972');
				break;
			case '/products/clorox-toilet-bowl-cleaner-tough-stain-remover/':
				fireFlsTag('3340030', 'produ035', 'cloro461');
				break;
			case '/products/clorox-blue-automatic-toilet-bowl-cleaner/':
				fireFlsTag('3340030', 'produ035', 'cloro070');
				break;
			case '/products/clorox-automatic-toilet-bowl-cleaner-bleach-and-blue/':
				fireFlsTag('3340030', 'produ035', 'cloro469');
				break;
			case '/products/clorox-germicidal-bleach/':
				fireFlsTag('3340030', 'produ035', 'cloro726');
				break;
			case '/products/clorox2/whats-new/':
				fireFlsTag('3330731', 'homep308', 'cloro023');
				break;
		}
	});

	/**
	 * Tags that fire on click
	 */
	// Initialize mousedown AKQA tags for all class 'fls-tag' but MUST have
	// valid id
	$('.fls-tag').each(function() {
		$(this).mousedown(function() {
			
			//Switch on the ID of the element
			switch (this.id) { 
				//Play button on promotions page
				case 'GA-Twitter':
					fireFlsTag('3340030', 'homep453', 'cloro436');
					break;
				case 'btn_home_mystain':
					fireFlsTag('3340030', 'homep453', 'cloro340');
					break;
				case 'joinFacebook':
					fireFlsTag('3340030', 'homep453', 'cloro291');
					break;
				case 'btn_prod_greenworks':
					fireFlsTag('3340030', 'produ035', 'cloro528');
					break;
				case 'GA-enterPABF':
					fireFlsTag('3340030', 'offer652', 'cloro684');
					break;
				case 'GA-enterPlay2Day':
					fireFlsTag('3340030', 'offer652', 'cloro974');
					break;
				case 'GA-enterNowSOW':
					fireFlsTag('3340030', 'offer652', 'cloro928');
					break;
				case 'GA-learnMoreIdeaContest':
					fireFlsTag('3340030', 'offer652', 'cloro108');
					break;
				case 'GA-downloadSong':
					fireFlsTag('3340030', 'offer652', 'cloro868');
					break;
				case 'GA-getNewsletter':
					fireFlsTag('3340030', 'offer652', 'cloro137');
					break;
				case 'GA-getCouponTW':
					fireFlsTag('3340030', 'offer652', 'cloro193');
					break;
				case 'gamePottyblox':
					fireFlsTag('3340030', 'games259', 'cloro235');
					break;
				case 'gameMahjongg':
					fireFlsTag('3340030', 'games259', 'cloro332');
					break;
				case 'gameSudoku':
					fireFlsTag('3340030', 'games259', 'cloro394');
					break;
				case 'gameGermWipeout':
					fireFlsTag('3340030', 'games259', 'cloro875');
					break;
				case 'gameCleanUpCraze':
					fireFlsTag('3340030', 'games259', 'cloro459');
					break;
				case 'gameSeek':
					fireFlsTag('3340030', 'games259', 'cloro669');
					break;
				case 'bleach-it-away-media-uncle-steve-visits':
					fireFlsTag('3340030', 'produ035', 'cloro143');
					break;
				case 'bleach-it-away-media-not-my-kid':
					fireFlsTag('3340030', 'produ035', 'cloro640');
					break;
				case 'bleach-it-away-media-potty':
					fireFlsTag('3340030', 'produ035', 'cloro059');
					break;
				case 'bleach-it-away-media-not-pregnant':
					fireFlsTag('3340030', 'produ035', 'cloro213');
					break;
			}
		})
	});
});

