/**
 * 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 akqa-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.scoopaway.com') == -1 
			&& $(location).attr('host').indexOf('staging.scoopaway.com') == -1 );

	/**
	 * Function that implements the tag.
	 */
	function fireAKQATag(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 click
	 */
	// Initialize mousedown AKQA tags for all class 'akqa-tag' but MUST have
	// valid id
	$('.akqa-tag').each(function() {
		$(this).mousedown(function() {
			
			//Switch on the ID of the element
			switch (this.id) { 
				case 'sa-litter-selector': 
					fireAKQATag('3329430', 'homep697', 'scoop583');
				    break;
				case 'sa-vet-log': 
					fireAKQATag('3329430', 'homep697', 'scoop914');
				    break;
				case 'sa-vet-finder': 
					fireAKQATag('3329430', 'homep697', 'scoop100');
				    break;
				case 'sa-guidelines': 
					fireAKQATag('3329430', 'homep697', 'scoop367');
				    break;
				case 'sa-products-tab': 
					fireAKQATag('3329430', 'homep697', 'scoop913');
				    break;
			}
		})
	});
});





