$(document).ready(
	function(){
		// 0 = count as page load
		$('.layer_tag').click( function() {
				fireWebtrendsTag(this.id, '0') ;
		});
		
		// 20 = download
		$('.download_tag').click( function() {
			var clickedId = this.id;
			
			fireWebtrendsTag(clickedId, '20');
			fireDoubleClickTag(clickedId);
		});
		
		// 21 = anchor click
		$('.anchor_tag').click( function() {
				fireWebtrendsTag(this.id, '21');
		});
		
		// 23 = mailto
		$('.mailto_tag').click( function() {
				fireWebtrendsTag(this.id, '23');
		});
		
		// 24 = off site link
		$('.offsite_tag').click( function() {
				fireWebtrendsTag(this.id, '24');
		});
		
		// 100 = click
		$('.click_tag').click( function() {
			// Note that we need to call these in a timeout or else the tags won't get fired correctly 
			// on the redirect. Since we're calling these in a timeout, we need to save this.id in a variable
			// because this may have changed by the time the timeout calls the function.
			var clickedId = this.id;
			
			setTimeout(function() {fireWebtrendsTag(clickedId, '100'); }, 50);
			setTimeout(function() {fireDoubleClickTag(clickedId); }, 50);
		});
	});


function fireWebtrendsTag(t, s) {
	dcsMultiTrack('DCS.dcsuri', '/clicktag/' + t ,'WT.ti', t,'WT.dl', s );
}

function fireWebtrendsFormTag(element, field, si_x) {
	dcsMultiTrack('DCS.dcsuri', element, 'WT.ti', field,'WT.si_n', 'RegistrationForm', 'WT.si_x', si_x );
}

function fireDoubleClickTag(id) {
	// a map where key = click tag id, value = unique arg for DoubleClick tracking
	var map = { 
				'facebook_like_flumistonfacebook_global_click': ['pick2010', 'likeu195'],
				'facebook_visitflumistfacebookpage_mainstage_click': ['pick2010', 'mains161'],
				'email_con_share_submit': ['pick2010', 'email446'],
				'pi_con_head_download': ['pick2010', 'flumi884'],
				'productinformation_con_page_download': ['pick2010', 'flumi884'],
				'productinformation_con_foot_download': ['pick2010', 'flumi884'],
				'Registration_form_submit_click': ['pick2010', 'regclick'],
				'registration_form_load': ['pick2010', 'Register'],
				'ISI_con_head_click': ['pick2010', 'isi'],
				'doctor_questions_english_pdf_download': ['pick2010', 'downl826'],
				'doctor_questions_spanish_pdf_download': ['pick2010', 'downl573']
				};
	var mapRow = map[id];
	
	if (mapRow !== undefined) { 
		executeFloodlight(mapRow[0], mapRow[1]);
	}
}

function executeFloodlight(type, cat)
{
    var axel = Math.random();
    var a = axel * 10000000000000;
    var atImg = new Image();
    
    atImg.src = window.location.protocol + "//fls.doubleclick.net/activityi;src=2378231;type=" + type + ";cat=" + cat + ";ord=" + a + "?";
    return false;  
}



