/**
 * 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.
 */

//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.brita.com') == -1);


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

	$('body').append(apnd);
	
	//This will fire off only on a non-production site. Use it to
	//check that tags are firing.
	if (flsDebug && typeof console != 'undefined') { 
		console.log('QA FLS ' + flsSrc + ' ' + flsType + ' ' + flsCat + ' ' + u1);
	}
}

	
	
$(document).ready(function() {

	/**
	 * Tags that fire on landing
	 * 
	 */
	$('body').each(function() {
		//For debugging only. Should not do anything in production.
		if (flsDebug && typeof console != 'undefined') { 
			console.log('Body ID ' + this.id + ' ' + $(location).attr('pathname'));
		}
		switch ($(location).attr('pathname')) {
			case '/products/water-pitchers/grand/':
				fireFlsTag('1261211', 'fy12j489', 'pitch682');
				break;
			case '/products/filtering-bottle/brita-bottle/':
				fireFlsTag('3326219', 'produ463', 'filte883');
				break;
			case '/coupons/fr-2off-pre-print/':
				fireFlsTag('1261211', 'fy12j489', 'coupo139');
				break;
			case '/coupons/fr-1off-pre-print/':
				fireFlsTag('1261211', 'fy12j489', 'coupo186');
				break;
			default:
				break;
		}
	});

	/**
	 * Tags that fire on click
	 */
	$('.fls-tag').each(function() {
		$(this).mousedown(function() {
			//Switch on the ID of the element
			switch (this.id) {
				case 'register-button':
					fireFlsTag('1261211', 'fy12j489', 'regis980', '[Button]');
					break;
				case 'login-modal-window':
					fireFlsTag('1261211', 'fy12j489', 'login062', '[Button]');
				case 'btn_reminder':
					if (window.location.pathname == '/products/water-pitchers/grand/') {
						fireFlsTag('1261211', 'fy12j489', 'filte012', '[Button]');						
					}
					break;
				case 'side-nav-filter-reminders':
					if (window.location.pathname == '/products/water-pitchers/grand/') {
						fireFlsTag('1261211', 'fy12j489', 'filte959', '[Button]');						
					}
					break;
				default:
					break;
			}
		})
	});
	
	
});

