/**
* Code to handle the tracking of click elements
*/

$(document).ready (function() {
	
	
	if (typeof uri == 'undefined') { return; };
	
	// GLOBALS ++++++++++++++++++++++++++++++++++++++++++++++++++++

	//primary navigation
	$( 'div#primaryNavigation ul li ul a, div#primaryNavigation ul li h2 a' ).live( 'click', function(){
		var options = {
			pagenameg : pageTrackJSON[0].vars.pageName,
			linkname  : $.trim( $( this ).text()).replace( /\&/g, '').replace( /\s+|\//g, '-' )
		}
		fireMetrics( 'globalnav', options );
	});

	//footer navigation
	$( 'div#auxiliaryNavigation ul li a' ).live( 'click', function(){
		var options = {
			pagenameg : pageTrackJSON[0].vars.pageName,
			linkname  : $.trim( $( this ).text()).replace( /\&/g, '').replace( /\s+|\//g, '-' )
		}
		fireMetrics( 'globalfooter', options );
	});

	// global print CTA
	$('div.aa_print span.printCTA a, div.pageTopActions a.linkPrint').live( 'click', function(){
		options = {}
		if( uri == '/content/gmcom/home/article' )
			options = { 'article_name' : $( 'div.flexLeftContent h3:eq(0)' ).text() }
		fireMetrics( 'print', options );
	});

	//leftnav slide menu
	$( 'div#slideMenuContent a' ).live( 'click', function(){
		var options = {
			pagename : pageTrackJSON[0].vars.pageName,
			linkname : $.trim( $( this ).text()).replace( /\&/g, '').replace( /\s+|\//g, '-' )
		}
		fireMetrics( 'leftnav', options );
	});

	//-------------------------------------------------------------
	//brand landing pages
	$( 'body.brandpage div#thumbSwitchBckgndImage div.bottom ul.textLinks li.textItems a' ).click( function(){
		fireMetrics( 'BRAND_SEE_MORE_' + $( 'body' ).attr( 'id' ).toUpperCase(), { 'link_name' : $( this ).text()});
	});
	//-------------------------------------------------------------
	//browse by
	if( uri == '/content/gmcom/home/vehicles/browseByBrand' ||
		uri == '/content/gmcom/home/vehicles/browseByType'
	){
		//checkboxes
		$( 'ul[class*="col0"]' ).find( 'input' ).live( 'click', function(){
			if( fireTracking ){
				var type = '';
				switch( $( this ).parent().attr( 'class' )){
					case 'type':
						type = 'vehicle_type';
						break;
					case 'hp':
						type = 'horsepower';
						break;
					case 'cargo':
						type = 'capacity';
						break;
					default:
						type = $( this ).parent().attr( 'class' );
				}
				fireMetrics( type, { value : $( this ).val() });
			}
		});
		//price slider
		//putting the fire metrrics call in the plugin
		//reset button
		$( '.updateButtonContainer' ).live( 'click', function(){
			fireMetrics( 'reset' );
		});
		//links in the bottom row of the filter for non flash
		$( '.bottomRow a' ).live( 'click', function(){
			var name = "";
			switch( $( this ).text() ){
				case 'GM Fleet & Commercial':
					name = 'GM Fleet and Commercial';
					break;
				default:
					name = 'GM Certified Pre-owned';
			}
			fireMetrics( 'locate_other_dealers', { destination_name : name });
		});
		//the images I couldent get the jQuery live function to work
		function vehicleResultsImageClick(){
			$( 'ul#vehicleResults li a' ).click( function(){
				fireMetrics( 'baseball_card', { value : $( this ).attr( 'title' )});
			});
		}
		function vehicleResultsImageClickTimer(){
			if( $( 'ul#vehicleResults li a' ).length > 0 ){
				vehicleResultsImageClick();
			} else {
				setTimeout( function(){ vehicleResultsImageClickTimer()}, 100 );
			}
		}
		vehicleResultsImageClickTimer();
	}
	//-------------------------------------------------------------
	// baseball_cards
	options = {}
	if( typeof( brand ) != 'undefined' && typeof( model ) != 'undefined' ){
		options = { brand : brand.replace( '_', '-' ), model : model.replace( '_', '-' ) }; 
	}
	$('.modelpage div#thumb.otherImage').live('click', function() {
		if ($(this).find('img:first-child').css('display') == 'none') {
			fireMetrics('baseball_card_interior_image', options);
		} else {
			fireMetrics('baseball_card_exterior_image', options);
		}
	});
	$('.modelpage .buttonAdjust240 .callToAction .actionContainer a').live('click', function() {
		fireMetrics( 'exit_brand_site', options );
	});
	$( '.buildYourOwnCTA a' ).live( 'click', function(){
		fireMetrics( 'exit_build_your_own', options) ;
	});
	$( '.compareToCompetitionCTA a' ).live( 'click', function(){
		fireMetrics( 'exit_compare', options );
	});
	$( '.currentOffersCTA a' ).live( 'click', function(){
		fireMetrics( 'exit_current_offers', options );
	});

	$( '.selectAnotherCTA a' ).live( 'click', function(){
		fireMetrics( 'see_another_vehicle', options );
	});
	$( '#liveChat').live( 'click', function(){
		fireMetrics( 'click_to_chat', options);
	});
	
	if( uri.indexOf( "/content/gmcom/home/vision" ) != -1 ){
		// visionconfigpage content links
		$( 'body.visionconfigpage .cq-colctrl-lt1-c0 .text a, body.peoplepage .flexLeftContent .text a' ).live( 'click', function(){
			fireMetrics( 'content_links', { 'destination_name' : $( this ).text() });
		});
		// visionconfigpage gallery
		$( 'body.visionconfigpage div.actionContainer a' ).live( 'click', function(){
			fireMetrics( 'video_close_button' );
			$( "div.modalOffClick,div.shadedContainerPop" ).remove();
		});
		// visionconfigpage relatedResources
		$('.visionconfigpage .relatedResources a, body.peoplepage .relatedResources a').live('click', function() {
			fireMetrics( 'related_resources', { 'destination_name' : $( this ).text() });
		});
	}

	//-------------------------------------------------------------
	//diversity_links0
	//$( 'div.flexLeftContent a' ).live( 'click', function(){
	//	fireMetrics( 'exit', { 'destination_name' : $( this ).text() });
	//});
	//-------------------------------------------------------------
	//diversity
	if( uri.indexOf( '/content/gmcom/home/company/aboutGM/diversity' ) >= 0 ){
		if( !$( 'body' ).hasClass( 'contentpagetwocolumn' )){
			//console.log( 'in diversity tracking' );
			$( 'div#promoTileMedium a' ).live( 'click', function(){
				fireMetrics( 'diversity_promotile', { 'destination_name' : $( this ).find( 'img' ).attr( 'alt' ) });
			});
			$( 'div.cq-colctrl-lt1-c0 div.text a' ).live( 'click', function(){
				//console.log( "content link" );
				var destination_name = $( this ).text() == 'Read more' ? 'focus areas' : $( this ).text();
				var href = $( this ).attr( 'href' ),
					pat = /http:\/\/(www)?\.?(\w*)\./,
					test = pat.test( href ),
					result = pat.exec( href );
				if( test ){
					//console.log( 'diversity_exit' );
					fireMetrics( 'diversity_exit', { 'destination_name' : destination_name });
				} else {
					//console.log( 'diversity_internal' );
					fireMetrics( 'diversity_internal', { 'destination_name' : destination_name });
				}
			});
			$( 'div.shadedContainerPop div.wrapActionContainer a.actionContainer' ).live( 'click', function(){
				fireMetrics( 'video_close_button' );
			});
			$( 'a.button' ).live( 'click', function(){
				//alert( '->' + $( this ).text() + '<-' );
				switch( true ){
					case $( this ).attr( 'href' ).indexOf( 'diversity.html' ) >= 0 && $( this ).text().trim() != 'Back':
						fireMetrics( 'diversity_menu' );
						break;
					case $( this ).attr( 'href' ).indexOf( 'diversity.html' ) >= 0 && $( this ).text().trim() == 'Back':
						fireMetrics( 'back_button' );
						break;
					case $( this ).parents( '.wrapActionContainer' ).length > 0:
						fireMetrics( 'video_close_button' );
						break;
					case $( this ).attr( 'href' ).indexOf( 'careers' ) >= 0:
					case $( this ).attr( 'href' ).indexOf( 'facesofgm' ) >= 0:
					default:
						fireMetrics( 'diversity_exit', { destination_name : $( this ).text()});
						break;
				}
			});
			//related resources
			$( 'div.relatedResources a' ).live( 'click', function(){
				var href = $( this ).attr( 'href' ),
					pat = /http:\/\/(www)?\.?(\w*)\./,
					test = pat.test( href ),
					result = pat.exec( href );
				if( test ){
					fireMetrics( 'related_resources_exit', { related_resource_name : result[2] });
				} else {
					fireMetrics( 'related_resources', { related_resource_name : $( this ).text() });
				}
			});
		}
	}
	//gallery
	if( uri.indexOf( '/content/gmcom/home/company/aboutGM/diversity' ) >= 0 && $( 'ul.slideshow').length > 0 ){
		if( !$( 'body' ).hasClass( 'contentpagetwocolumn' )){
			//console.log( 'in diversity tracking' );		//fire the up gallery initaly
			$( 'ul.slideshow li.active' ).each( function(){
				fireMetrics( 'image_gallery_image', { image_name : $( this ).find( 'img' ).attr( 'alt' )});
			});
			//prev click
			$( 'div.galleryPrev' ).live( 'click', function(){
				fireMetrics( 'image_gallery_prev_arrow' );
				fireMetrics( 'image_gallery_image', { image_name : $( this ).parents( '.galleryWraper' ).find( 'ul.slideshow li.active' ).next().find( 'img' ).attr( 'alt' )});
			});
			//next click
			$( 'div.galleryNext' ).live( 'click', function(){
				fireMetrics( 'image_gallery_next_arrow' );
				fireMetrics( 'image_gallery_image', { image_name : $( this ).parents( '.galleryWraper' ).find( 'ul.slideshow li.active' ).next().find( 'img' ).attr( 'alt' )});
			});
			//number click
			$( 'div.controlNav a' ).live( 'click', function(){
				var text = $( this ).text();
				text = $( this ).index() == 0 ? "left-arrow" : text;
				text = $( this ).index() == $( this ).parent().children().length - 1 ? "right-arrow" : text;
				fireMetrics( 'image_gallery_number', { number_clicked : text });
				fireMetrics( 'image_gallery_image', { image_name : $( this ).parents( '.galleryWraper' ).find( 'ul.slideshow li.active' ).next().find( 'img' ).attr( 'alt' )});
			});
		}
	}

	//-------------------------------------------------------------
	// Pillar page - design_technology - environment1 - community_education - quality_safety
	if( uri == '/content/gmcom/home/vision/design_technology'   ||
		uri == '/content/gmcom/home/vision/environment1'        ||
		uri == '/content/gmcom/home/vision/community_education' ||
		uri == '/content/gmcom/home/vision/quality_safety'
	){
		$( 'ul#stopLabels li a' ).live( 'click', function(){
			fireMetrics( 'placement_links', { 'placement_number' : $( this ).parent().index()});
		});
		$( 'ul#sliderContent li a.button' ).live( 'click', function(){
			var text = $( this ).text();
			text = text.toLowerCase().replace( /\s+|-/g, '_' );
			fireMetrics( text );
		});
		$( 'div#sliderCTAWraper a' ).live( 'click', function(){
			fireMetrics( 'slider_cta', { link_name : $( this ).text()});
		});
	}

	//-------------------------------------------------------------
	// Pillar article page - design_technology - environment1 - community_education - quality_safety
	if( uri == '/content/gmcom/home/vision/community_education/education_project' ){
		$( '.relatedResources a, .actionContainer a' ).live( 'click', function(){
			fireMetrics( 'exit', { 'destination_name' : $( this ).text() });
		});
	}

	//-------------------------------------------------------------
	// board_of_directors0
	if (uri == "/content/gmcom/home/company/aboutGM/board_of_directors0") {
		// tracking for text links
		$('.parsys.cta a[href="/content/dam/gmcom/COMPANY/About_GM/Board_of_Directors/pdfs/Audit.pdf"]').live('click', function() {
			fireMetrics('download_audit');
		});
		$('.parsys.cta a[href="/content/dam/gmcom/COMPANY/About_GM/Board_of_Directors/pdfs/Executive%20Compensation.pdf"]').live('click', function() {
			fireMetrics('download_executive_compensation');
		});
		$('.parsys.cta a[href="/content/dam/gmcom/COMPANY/About_GM/Board_of_Directors/pdfs/Public%20Policy.pdf"]').live('click', function() {
			fireMetrics('download_public_policy');
		});
		$('.parsys.cta a[href="/content/dam/gmcom/COMPANY/About_GM/Board_of_Directors/pdfs/Directors%20and%20Corporate%20Governance.pdf"]').live('click', function() {
			fireMetrics('download_corporate_governance');
		});
		$('.parsys.cta a[href="/content/dam/gmcom/COMPANY/About_GM/Board_of_Directors/pdfs/Finance%20%26%20Risk%20Policy.pdf"]').live('click', function() {
			fireMetrics('download_fianace_risk_policy');
		});
	} // END board_of_directors0
	
	//-------------------------------------------------------------
	// gm_sustainability
	if( uri == "/content/gmcom/home/company/aboutGM/corporate_responsiblity/gm_sustainability" ){
		$( 'a.button' ).live( 'click', function(){
			fireMetrics( 'exit' );
		});
	}

	//-------------------------------------------------------------
	// dealerLocator
	if (uri == "/content/gmcom/home/vehicles/dealerLocator") {
		
		// initial set
		$('div.dealerSearchRefined select#searchRadius').live('change', function() {
			fireMetrics( 'mileage_radius', { 'radius_selected' : $( this ).children( ':selected' ).val() });
		});
		$('div.dealerSearchRefined ul#brandSelection input.ui-helper-hidden-accessible').live('change', function() {
			fireMetrics( 'specific_brand_dealers', { 'brand_name_selected' : $( this ).val() });
		});
		$('div.dealerSearchRefined ul#dl_servicelist input.ui-helper-hidden-accessible').live('change', function() {
			fireMetrics( 'dealer_type', { 'dealer_type_selected' : $( this ).siblings( 'label' ).text() });
		});
		
		// results set
		$('div#criterial_filter_area select#searchRadius').live('change', function() {
			fireMetrics( 'results_mileage_radius', { 'radius_selected' : $( this ).children( ':selected' ).val() });
		});
		$('div#criterial_filter_area ul#brandSelection input.ui-helper-hidden-accessible').live('change', function() {
			fireMetrics( 'results_specific_brand_dealers', { 'brand_name_selected' : $( this ).val() });
		});
		$('div#criterial_filter_area ul#dl_servicelist input.ui-helper-hidden-accessible').live('change', function() {
			fireMetrics('results_dealer_type', { 'dealer_type_selected' : $( this ).siblings( 'label' ).text() });
		});
		$('select#sortOption').live('change', function() {
			fireMetrics('results_dealer_sort_by', { 'sort_by_results' : $( this ).children( ':selected' ).val() });
		});
		//To prevent the firing of this twice I am adding the listner to the footer one. Both dropdowns cahnge when you change the other.
		$('div#dl_footer_paging_id select#dealersPerPageOption').live('change', function() {
			fireMetrics('results_dealer_view', { 'view_per_page_results' : $( this ).children( ':selected' ).val() });
		});
		
		$( 'ul#mds-cmp-dealer_list div.ctaContainer a.dlImgButton.btnImg_SI').live( 'click', function(){
			var href = $( this ).attr( 'href' ),
				pat = /www\.(\w*)\.com/,
				result = pat.exec( href );
			fireMetrics( 'results_dealer_search_inventory', { 'brand' : result[1] });
		});
		$( 'ul#mds-cmp-dealer_list div.ctaContainer a.dlImgButton.btnImg_RAQ').live( 'click', function(){
			var href = $( this ).attr( 'href' ),
				pat = /www\.(\w*)\.com/,
				result = pat.exec( href );
			fireMetrics( 'results_dealer_request_a_quote', { 'brand' : result[1] });
		});
		
		$('ul.dl_search_result_list  ul.dealer-links li a').live('click', function() {
			fireMetrics( 'results_dealer_dealer_website', { 'dealer_name' : $( this ).parents( 'form' ).find( '#dealerName' ).text() });
		});
		
		$('p.btn_nba_1 a').live('click', function() {
			fireMetrics('map_page');
		});
		
		$( 'div#dealer_tmp a.dlImgButton.btnImg_SI').live( 'click', function(){
			var href = $( this ).attr( 'href' ),
				pat = /www\.(\w*)\.com/,
				result = pat.exec( href );
			fireMetrics( 'map_dealer_search_inventory', { 'brand' : result[1] });
		});
		$( 'div#dealer_tmp a.dlImgButton.btnImg_RAQ').live( 'click', function(){
			var href = $( this ).attr( 'href' ),
				pat = /www\.(\w*)\.com/,
				result = pat.exec( href );
			fireMetrics( 'map_dealer_request_a_quote', { 'brand' : result[1] });
		});
		$('div#dealer_tmp ul.dealer-links li a').live('click', function() {
			fireMetrics( 'map_dealer_dealer_website', { 'dealer_name' : $( this ).parents( 'form' ).find( '#dealerName' ).text() });
		});

		//promo Tiles
		$( '.promoTile a' ).live( 'click', function(){
			var href = $( this ).attr( 'href' ),
				pat = /www\.(\w*)\.com/,
				result = pat.exec( href );
			fireMetrics( 'locate_other_dealers', { 'destination_name' : result[1] });
		});

	} // END dealerLocator
	
	//-------------------------------------------------------------
	// contactUs
	if (uri == "/content/gmcom/home/toolbar/contactUs") {
		$('body#contactUs div.shadedContainer div.contact-us-brand-section a').live('click', function(){
			var href = $( this ).attr( 'href' ),
				pat = /www\.(\w*)\./,
				result = pat.exec( href );
			fireMetrics('contact_us_exit', { 'destination_name' : result[1] });
		});
		$( 'body#contactUs div.cq-colctrl-lt1-c1 div.cta_shaded_container a' ).live('click', function(){
			var href = $( this ).attr( 'href' ),
				pat = /www\.(\w*)\./,
				result = pat.exec( href );
			if( result && result[1].length > 0 ){
				fireMetrics('contact_us_exit', { 'destination_name' : result[1] });
			}
		});
	} // END contactUs
	
	//-------------------------------------------------------------
	// contactUsForm
	if (uri == "/content/gmcom/home/toolbar/contactUsForm") {
		$('body#contactUsForm a.help-me-decide-submit-button').live('click', function() {
			var options = {},
				exit = false,
				pat = /www/;
			if( contactUsJSON[$('span.ui-radio-state-checked').prev().val()] ){
				switch( typeof( contactUsJSON[$('span.ui-radio-state-checked').prev().val()] )){
					case 'string':
						exit = pat.test( contactUsJSON[$('span.ui-radio-state-checked').prev().val()] );
						options = { 'destination_name' : contactUsJSON[$('span.ui-radio-state-checked').prev().val()] }
						break;
					case 'object':
						exit = true;
						options = { 'destination_name' : contactUsJSON[$('span.ui-radio-state-checked').prev().val()].selects[$('span.ui-radio-state-checked').parent().next().find( 'select :selected').val()] }
						break;
					default:
						options = { 'destination_name' : 'other questions' }
				}
			} else {
				options = { 'destination_name' : 'other questions' }
			}
			if( exit ){
				fireMetrics('contact_us_form_submit', options );
			} else {
				fireMetrics('contact_us_form_submit', options );
			}
		});
		$( 'body#contactUsForm div.submitButtonContainer div#submitButton a' ).live( 'click', function(){
			fireMetrics('contact_us_form_submit', { 'destination_name' : '' } );
		});
	} // END contactUsForm
	
	//-------------------------------------------------------------
	// global sites
	if( uri == "/content/gmcom/home/toolbar/allGMSites" ){
		$( 'ul.global-sites-brand-list a' ).live( 'click', function(){
			var href = $( this ).attr( 'href' ),
				pat = /www\.(\w*)\./,
				result = pat.exec( href );
			fireMetrics('global_sites_exit', { 'country' : 'United States', 'destination_name' : result[1] });
		});
		$( 'div.global-sites-menu-block-mask a' ).live( 'click', function(){
			fireMetrics('global_sites_exit', { 'country' : $( 'ul.global-sites-menu-block-country li.global-sites-menu-item-active' ).text(), 'destination_name' : $( this ).text() });
		});
		$( 'div.branding_call_to_action a' ).live( 'click', function(){
			var href = $( this ).attr( 'href' ),
				pat = /www/,
				exit = pat.test( href );
			if( exit ){
				fireMetrics( 'global_exit', { 'destination_name' : $( this ).parents( 'div.midMid:eq(0)' ).find( 'h3' ).text() });
			} else {
				fireMetrics( 'global_internal', { 'destination_name' : $( this ).parents( 'div.midMid:eq(0)' ).find( 'h3' ).text() });
			}
		});
	}

	//-------------------------------------------------------------
	// Privacy
	if( uri == "/content/gmcom/home/toolbar/privacyStatement" ){
		$( 'a + .parbase a' ).live( 'click', function(){
			var href = $( this ).attr( 'href' ),
				pat = /http:\/\/(www)?\.?(\w*)\./,
				test = pat.test( href ),
				result = pat.exec( href );
			if( test ){
				fireMetrics( 'exit', { destination_name : result[2] });
			} else {
				fireMetrics( 'links', { link_name : $( this ).text() });
			}
		});
	}

	//Below this point only tracking blocks that have been made generic ie not page specfic but work for a template or some other item used on all pages of a given type or style.
	//-------------------------------------------------------------
	//Tile page
	if( $( 'body' ).hasClass( 'tile' )){
		$( '.mini_shaded_container a' ).live( 'click', function(){
			fireMetrics( 'internal', { tile_name : $( this ).parents( '.mini_shaded_container' ).find( 'h3' ).text()});
		});
	}
	//-------------------------------------------------------------
	//Bottom Tab Container
	if( $( 'body' ).hasClass( 'tabpage' )){
		//Tabs
		$( 'ul.tabs li' ).live( 'click', function(){
			var page = 'tab_page',
				value = $( 'ul#bottomTabContainerData > li' ).eq( $( this ).index() ).attr( 'title' );
			fireMetrics( page, { name : value });
		});
		//Arrows
		$( '.bottomTabContainerNext' ).live('click', function(){
			var page = 'tab_page';
			if( $( '.btActive:eq(0)' ).hasClass( 'first' ) && $( '.btActive:eq(1)' ).hasClass( 'last' )){
				value = $( 'ul#bottomTabContainerData > li' ).eq( $( 'ul.tabs li.first' ).index() ).attr( 'title' );
			} else {
				value = $( 'ul#bottomTabContainerData > li' ).eq( $( 'ul.tabs li:eq(0).btActive' ).next().index() ).attr( 'title' );
			}
			fireMetrics( page, { name : value });
		});
		$( '.bottomTabContainerPrev' ).live('click', function(){
			var page = 'tab_page';
			if( $( '.btActive:eq(0)' ).hasClass( 'first' ) && $( '.btActive:eq(1)' ).hasClass( 'last' )){
				value = $( 'ul#bottomTabContainerData > li' ).eq( $( 'ul.tabs li.last' ).index() ).attr( 'title' );
			} else {
				value = $( 'ul#bottomTabContainerData > li' ).eq( $( 'ul.tabs li:eq(1).btActive' ).prev().index() ).attr( 'title' );
			}
			fireMetrics( page, { name : value });
		});
		//links weather thay are cta looking buttons or triditional links
		$( 'ul.content li a:not(.modalPopOutTarget)' ).live( 'click', function(){
			var href = $( this ).attr( 'href' ),
				pat = /^http/,
				test = pat.test( href ),
				page = test ? 'exit' : 'internal';
			fireMetrics( page, { link_text : $( this ).text() });
		});
		//links that trigger modals
		$( 'ul.content li a.modalPopOutTarget' ).live( 'click', function(){
			fireMetrics( 'modal', { link_text : $( this ).text() });
		});
	}

	//-------------------------------------------------------------
	//archive
	if( $( 'body' ).hasClass( 'newsarchivepage' )){
		//Dropdowns
		$( 'select' ).change( function(){
			var id = '',
				selection = $( this ).val();
			switch( $( this ).attr( 'id' )){
				case 'filtersSelect1':
					id = 'filter';
					break;
				case 'view-by-select-1':
					id = 'view';
					break;
			}
			fireMetrics( id, { selection : selection });
		});
		//Pagination
		$( 'div.controlNav a' ).live( 'click', function(){
			var text = $( this ).text();
				text = $( this ).index() == 0 ? "left-arrow" : text;
				text = $( this ).index() == $( this ).parent().children().length - 1 ? "right-arrow" : text;
			fireMetrics( 'number', { number : text });
		});
		//Article
		$( '.article a' ).click( function(){
			var additional = $( this ).parent().hasClass( 'callToAction' ) ? ' Read More' : ''
			fireMetrics( 'internal', { name : $( this ).parents( '.article' ).find( 'h3 a' ).text() + additional });
		});
	}

	//-------------------------------------------------------------
	//contentpagetwocolumn
	if( $( 'body' ).hasClass( 'contentpagetwocolumn' )){
		//console.log( 'inside contentpagetwocolumn tracking' );
		$( 'div#promoTileMedium a' ).live( 'click', function(){
			fireMetrics( 'promotile', { 'destination_name' : $( this ).find( 'img' ).attr( 'alt' ) });
		});
		$( 'div.flexLeftContent div.text a' ).live( 'click', function(){
			var $this = $( this ),
				destination_name = $( this ).text().trim(),
				href = $( this ).attr( 'href' ),
				pat = /http:\/\/(www)?\.?(\w*)\./,
				pat2 = /(\w*)\.pdf$/i,
				test = pat.test( href ),
				test2 = pat2.test( href ),
				result = pat.exec( href );
			destination_name =  $( 'div.flexLeftContent div.text a:contains(' + destination_name + ')').length > 1 ? destination_name + ' ' + $( this ).index( 'div.flexLeftContent div.text a:contains(' + destination_name + ')' ) : destination_name;
				result2 = pat2.exec( href );
			if( test ){
				fireMetrics( 'exit', { 'destination_name' : destination_name });
			} else {
				if( test2 ){
					fireMetrics( 'pdf_internal', { 'pdf_name' : result2[1] });
				} else {
					fireMetrics( 'internal', { 'destination_name' : destination_name });
				}
			}
		});
		$( 'a.button' ).live( 'click', function(){
			//alert( '->' + $( this ).text() + '<-' );
			switch( true ){
				case $( this ).parents( '.wrapActionContainer' ).length > 0:
					fireMetrics( 'video_close_button' );
					break;
				default:
					var destination_name = $( this ).text();
					var href = $( this ).attr( 'href' ),
						pat = /http:\/\/(www)?\.?(\w*)\./,
						test = pat.test( href ),
						result = pat.exec( href );
					if( test ){
						fireMetrics( 'exit', { 'destination_name' : destination_name });
					} else {
						fireMetrics( 'internal', { 'destination_name' : destination_name });
					}
					//fireMetrics( 'exit', { destination_name : $( this ).text()});
					break;
			}
		});
		//related resources
		$( 'div.relatedResources a' ).live( 'click', function(){
			var href = $( this ).attr( 'href' ),
				pat = /http:\/\/(www)?\.?(\w*)\./,
				test = pat.test( href ),
				result = pat.exec( href );
			if( test ){
				fireMetrics( 'related_resources_exit', { related_resource_name : result[2] });
			} else {
				fireMetrics( 'related_resources', { related_resource_name : $( this ).text() });
			}
		});
		if( $( 'ul.slideshow').length > 0 ){
			//fire the up gallery initaly
			$( 'ul.slideshow li.active' ).each( function(){
				fireMetrics( 'gallery_image', { image_name : $( this ).find( 'img' ).attr( 'alt' )});
			});
			//prev click
			$( 'div.galleryPrev' ).live( 'click', function(){
				fireMetrics( 'gallery_prev_arrow' );
				fireMetrics( 'gallery_image', { image_name : $( this ).parents( '.galleryWraper' ).find( 'ul.slideshow li.active' ).next().find( 'img' ).attr( 'alt' )});
			});
			//next click
			$( 'div.galleryNext' ).live( 'click', function(){
				fireMetrics( 'gallery_next_arrow' );
				fireMetrics( 'gallery_image', { image_name : $( this ).parents( '.galleryWraper' ).find( 'ul.slideshow li.active' ).next().find( 'img' ).attr( 'alt' )});
			});
			//number click
			$( 'div.controlNav a' ).live( 'click', function(){
				var text = $( this ).text();
				text = $( this ).index() == 0 ? "left-arrow" : text;
				text = $( this ).index() == $( this ).parent().children().length - 1 ? "right-arrow" : text;
				fireMetrics( 'gallery_number', { number_clicked : text });
				fireMetrics( 'gallery_image', { image_name : $( this ).parents( '.galleryWraper' ).find( 'ul.slideshow li.active' ).next().find( 'img' ).attr( 'alt' )});
			});
		}
	}
});
