/*** EVENT TRACKING ***/
var _gaq = _gaq || [];
var the_body = document.body;
$(document).ready(function(){

	/** SITE **/
	$('#main_nav li a').click(function(e){
		// Top Nav Links
		_gaq.push([ '_trackEvent', "header", "nav_link", $(this).parent().attr('id'), window.location.href ]);
	});
	$('#site_search form').submit(function(e){
		// Search Terms
		_gaq.push([ '_trackEvent', "header", "search_query", $('#searchbox').val(), window.location.href ]);
	});
	$('#pinned_footer .grid_8 li a').click(function(e){
		// Bottom Nav Links
		_gaq.push([ '_trackEvent', "footer", "product_link", $(this).text(), window.location.href ]);
	});
	$('#pinned_footer .grid_4 li a').click(function(e){
		// Bottom Social Links
		_gaq.push([ '_trackEvent', "footer", "social_link", $(this).parent().attr('id'), window.location.href ]);
	});
	
	/** HOME **/
	if(the_body.className.indexOf('home') > -1) {
		// Learn/Assess/Choose tab_open event is found in script.js on line 147.
		$('#home_menus .pop_up ul li a').click(function(e){
			// Tab Links
			_gaq.push([ '_trackEvent', "home", "tab_links", $(this).parent().parent().siblings('.hgroup').find('h2').text(), $(this).text() ]);
		});
	}
	
	/** OUR COMPANY **/
	// no events for this section
	
		/** OUR COMPANY - HISTORY **/
		// no events for this section
		
		/** OUR COMPANY - CLEAN ENERGY **/
		// no events for this section
		
		/** OUR COMPANY - LEADERSHIP **/
		// no events for this section
	
	/** PRODUCTS **/
	// no events for this section
	
		/** PRODUCTS - PURECELL **/
		if(the_body.className.indexOf('purecell400') > -1) { 
			$('body.purecell400 #support_nav li a').click(function(e){
				// SubNav Links
				_gaq.push([ '_trackEvent', "product_purecell", "nav_links", $(this).text() ]);
			});
			$('body.purecell400 #markets_served a.marketservedppt').click(function(e){
				// Slideshow Download (Markets Served Tab)
				_gaq.push([ '_trackEvent', "product_purecell", "slideshow_download", "", "" ]);
			});
			$('body.purecell400 dl.datasheets dt a').click(function(e){
				// Datasheet Download (Support/FAQ Tabs)
				_gaq.push([ '_trackEvent', "product_purecell", "datasheet_download", $(this).text(), $(this).parent().parent().parent().parent().parent().attr('id') ]);
			});
			$('body.purecell400 #faq .faq dl dt a.toggle').click(function(e){
				// FAQ Open (FAQ Tab)
				if (  $(this).parent().siblings('dd:eq(' + ($(this).attr('itemid') - 1) + ')').css("height") == "1px" ) {
					_gaq.push([ '_trackEvent', "product_purecell", "faq_open", $(this).text(), "" ]);
				}
			});
		}
		
		/** PRODUCTS - TRANSPORTATION **/
		// no events for this section
		
			/** PRODUCTS - AUTOMOTIVE **/
			if(the_body.className.indexOf('automotive') > -1) { 
				$('body.automotive #support_nav li a').click(function(e){
					// SubNav Links
					_gaq.push([ '_trackEvent', "product_auto", "nav_links", $(this).text() ]);
				});
				$('body.automotive dl.datasheets dt a').click(function(e){
					// Datasheet Download (Support/FAQ Tabs)
					_gaq.push([ '_trackEvent', "product_auto", "datasheet_download", $(this).text(), $(this).parent().parent().parent().parent().parent().attr('id') ]);
				});
				$('body.automotive #faqs .faq dl dt a.toggle').click(function(e){
					// FAQ Open (FAQ Tab)
					if (  $(this).parent().siblings('dd:eq(' + ($(this).attr('itemid') - 1) + ')').css("height") == "1px" ) {
						_gaq.push([ '_trackEvent', "product_auto", "faq_open", $(this).text(), "" ]);
					}
				});
			}
			
			/** PRODUCTS - FLEET VEHICLES **/
			if(the_body.className.indexOf('fleetvehicles') > -1) { 
				$('body.fleetvehicles #support_nav li a').click(function(e){
					// SubNav Links
					_gaq.push([ '_trackEvent', "product_fleet", "nav_links", $(this).text() ]);
				});
				$('body.fleetvehicles dl.datasheets dt a').click(function(e){
					// Datasheet Download (Support/FAQ Tabs)
					_gaq.push([ '_trackEvent', "product_fleet", "datasheet_download", $(this).text(), $(this).parent().parent().parent().parent().parent().attr('id') ]);
				});
				$('body.fleetvehicles #faqs .faq dl dt a.toggle').click(function(e){
					// FAQ Open (FAQ Tab)
					if (  $(this).parent().siblings('dd:eq(' + ($(this).attr('itemid') - 1) + ')').css("height") == "1px" ) {
						_gaq.push([ '_trackEvent', "product_fleet", "faq_open", $(this).text(), "" ]);
					}
				});
			}
		
		/** PRODUCTS - SPACE **/
		if(the_body.className.indexOf('space') > -1) { 
			$('body.space #support_nav li a').click(function(e){
				// SubNav Links
				_gaq.push([ '_trackEvent', "product_space", "nav_links", $(this).text() ]);
			});
			$('body.space dl.datasheets dt a').click(function(e){
				// Datasheet Download (Support/FAQ Tabs)
				_gaq.push([ '_trackEvent', "product_space", "datasheet_download", $(this).text(), $(this).parent().parent().parent().parent().parent().attr('id') ]);
			});
			$('body.space #faqs .faq dl dt a.toggle').click(function(e){
				// FAQ Open (FAQ Tab)
				if (  $(this).parent().siblings('dd:eq(' + ($(this).attr('itemid') - 1) + ')').css("height") == "1px" ) {
					_gaq.push([ '_trackEvent', "product_space", "faq_open", $(this).text(), "" ]);
				}
			});
		}
	
	/** PRESS ROOM **/
	if(the_body.id.indexOf('overview') > -1 && the_body.className.indexOf('news_overview') > -1) { 
		$('body.news_overview#overview #bottom .third:eq(0) p a.cont').click(function(e){
			// Press Room
			_gaq.push([ '_trackEvent', "pressroom", "twitter_follow", "main_pressroom", "" ]);
		});
	}
	
		/** PRESS ROOM - ARTICLES **/
		if(the_body.id.indexOf('single') > -1 && the_body.className.indexOf('news') > -1) { 
			$('body.news#single #twitter-follow').click(function(e){
				// Article/PR Single Entry Sidebar Twitter Link
				_gaq.push([ '_trackEvent', "pressroom", "twitter_follow", window.location.href ]);
			});
		}
		
		/** PRESS ROOM - PRESS RELEASES **/
		if(the_body.id.indexOf('archive-pr') > -1) { 
			$('body#archive-pr #news-main #contacts a').click(function(e){
				// Top Email links
				_gaq.push([ '_trackEvent', "press_releases", "contact_email", $(this).attr('title') + "@" + $(this).attr('itemid'), "main" ]);
			});
			$('body#archive-pr #news-main .post .pr-pdf a').click(function(e){
				// PR Read PDF
				_gaq.push([ '_trackEvent', "press_releases", "pr_read_pdf", $(this).parent().parent().find('p:eq(1)').text(), "" ]);
			});
			$('body#archive-pr #news-main .post .pr-read a').click(function(e){
				// PR Read Online
				_gaq.push([ '_trackEvent', "press_releases", "pr_read_online", $(this).parent().parent().find('p:eq(1)').text(), "" ]);
			});
		}
		
		/** PRESS ROOM - EVENTS **/
		if(the_body.id.indexOf('events') > -1) { 
			$('body.news#events #upcoming-events .event .details p:eq(0) a').click(function(e){
				// Event Website Link
				_gaq.push([ '_trackEvent', "press_events", "event_website_link", $(this).parent().parent().parent().find('h4.event-title').text(), $(this).attr('href') ]);
			});
			$('body.news#events #upcoming-events .event .details p:eq(1) a').click(function(e){
				// Event Website Link
				_gaq.push([ '_trackEvent', "press_events", "event_utc_contact", $(this).parent().parent().parent().find('h4.event-title').text(), $(this).attr('title') + "@" + $(this).attr('itemid') ]);
			});
		}
		
		/** PRESS ROOM - GALLERY **/
		if (the_body.className.indexOf('gallery') > -1) {
			$('body.gallery #contact-info a').click(function(e){
				// Right Sidebar Email links
				_gaq.push([ '_trackEvent', "press_gallery", "contact_email", $(this).attr('title') + "@" + $(this).attr('itemid'), "" ]);
			});
		}
	
	/** KNOWLEDGE LIBRARY **/
	// no events for this section
		/** KNOWLEDGE LIBRARY - TECHNICAL INFORMATION **/
		if (the_body.className.indexOf('mediaDownloads') > -1) {
			// Hi-Res Photos
			$('body.mediaDownloads div.caption a').click(function(e){
				if ($(this).parent('div').hasClass('forbidden')) {
					_gaq.push([ '_trackEvent', "press_downloads", "photo_download_private", $(this).prevAll('h5').text()/*, $(this).parent('div.caption').attr('itemid')*/ ]);
				} else {
					_gaq.push([ '_trackEvent', "press_downloads", "photo_download_private_granted", $(this).prevAll('h5').text()/*, $(this).parent('div.caption').attr('itemid')*/ ]);
				}
			});

			// Hi-Res Videos
			$('body.mediaDownloads #video-list p.clickable').click(function(e){
				if ($(this).hasClass('forbidden')) {
					_gaq.push([ '_trackEvent', "press_downloads", "video_download_private", $(this).prevAll('h4').text()/*, $(this).attr('itemid')*/ ]);
				} else {
					_gaq.push([ '_trackEvent', "press_downloads", "video_download_private_granted", $(this).prevAll('h4').text()/*, $(this).attr('itemid')*/ ]);
				}
			});

			// Tech spec pdfs
			$('body.mediaDownloads dl.clickable').click(function(e){
				if ($(this).hasClass('private')) {
					if ($(this).hasClass('forbidden')) {
						_gaq.push([ '_trackEvent', "press_downloads", "pdf_download_private", $(this).find('time').text()/*, $(this).attr('itemid')*/ ]);
					} else {
						_gaq.push([ '_trackEvent', "press_downloads", "pdf_download_private_granted", $(this).find('time').text()/*, $(this).attr('itemid')*/ ]);
					}
				} else {
					_gaq.push([ '_trackEvent', "press_downloads", "pdf_download", $(this).find('time').text()/*, $(this).attr('itemid')*/ ]);
				}
			});

		}


		/** KNOWLEDGE LIBRARY - TECHNICAL INFORMATION **/
		if (the_body.className.indexOf('prodtech') > -1) {
			$('body.prodtech #prod_tech_docs dl.clickable').click(function(e){
				if ($(this).hasClass('private')) {
					if ($(this).hasClass('forbidden')) {
						_gaq.push([ '_trackEvent', "kl_techinfo", "pdf_download_private", $(this).find('time').text()/*, $(this).attr('itemid')*/ ]);
					} else {
						_gaq.push([ '_trackEvent', "kl_techinfo", "pdf_download_private_granted", $(this).find('time').text()/*, $(this).attr('itemid')*/ ]);
					}
				} else {
					// Tech Spec PDFs
					_gaq.push([ '_trackEvent', "kl_techinfo", "pdf_download", $(this).find('time').text()/*, $(this).attr('itemid')*/ ]);
				}
			});
		}
		
		/** KNOWLEDGE LIBRARY - FAQS **/
		if (the_body.className.indexOf('faqs') > -1) {
			$('body.faqs #faqs .faq dl dt a.toggle').click(function(e){
				// FAQ Open (FAQ Tab)
				if (  $(this).parent().siblings('dd:eq(' + ($(this).attr('itemid') - 1) + ')').css("height") == "1px" ) {
					_gaq.push([ '_trackEvent', "kl_faqs", "faq_open", $(this).text(), "" ]);
				}
			});
		}
		
		/** KNOWLEDGE LIBRARY - MEDIA **/
		if (the_body.className.indexOf('media') > -1) {
			$('body.media #sidebar .pdf-list a').click(function(e){
				// Brochure Link
				_gaq.push([ '_trackEvent', "kl_media", "brochure_download", $(this).text(), $(this).attr('href') ]);
			});
			$('body.media #sidebar dl dd a.obs').click(function(e){
				// Email Link
				_gaq.push([ '_trackEvent', "kl_media", "contact_email", $(this).attr('title') + "@" + $(this).attr('itemid'), "" ]);
			});
			$('body.media #video a').click(function(e){
				// YT Subscribe
				_gaq.push([ '_trackEvent', "kl_media", "yt_subscribe_button", "", "" ]);
			});
			$('body.media #video-list li a').click(function(e){
				// Video Lightbox Open
				_gaq.push([ '_trackEvent', "kl_media", "video_lightbox", $(this).parents('li').find('h4 a').text(), "" ]);
			});
		}
	
	/** CONTACT **/
	if (the_body.className.indexOf('contact') > -1) {
		$('body.contact #mc-map .orange_btn').click(function(e){
			// Google Maps Link
			_gaq.push([ '_trackEvent', "contact", "directions_link", "", "" ]);
		});
		$('body.contact #mc-map #btn3').click(function(e){
			// Suppliers PPT Download
			_gaq.push([ '_trackEvent', "contact", "suppliers_download", "", "" ]);
		});
		$('body.contact #contact-us a').click(function(e){
			// Left Sidebar Email links
			_gaq.push([ '_trackEvent', "contact", "contact_email", $(this).attr('title') + "@" + $(this).attr('itemid'), "" ]);
		});
		$('body.contact #mc-contact form').submit(function(e){
			// Contact form submit
			_gaq.push([ '_trackEvent', "contact", "form_submission", "", "" ]);
		});
	}
	
		/** CONTACT - CAREERS **/
		if(the_body.id.indexOf('careers') > -1 && the_body.className.indexOf('contact') > -1) { 
			$('body.contact#careers #lead-in .post a').click(function(e){
				// UTC Jobs Link (intext)
				_gaq.push([ '_trackEvent', "contact_careers", "utcjobs_link", "link", "" ]);
			});
			$('body.contact#careers #secondary p a').click(function(e){
				// UTC Jobs Link (button)
				_gaq.push([ '_trackEvent', "contact_careers", "utcjobs_link", "button", "" ]);
			});
			$('body.contact#careers #utc_esp a').click(function(e){
				// UTC ESP Link (intext)
				_gaq.push([ '_trackEvent', "contact_careers", "utcesp_link", $(this).text(), "" ]);
			});
		}
		
		/** CONTACT - INVESTORS **/
		if (the_body.className.indexOf('stock') > -1) {
			$('body.stock #careers-main #lead-in .post a').click(function(e){
				// UTC Investor Relations Link
				_gaq.push([ '_trackEvent', "contact_investors", "utcinv_link", "link", "" ]);
			});
			$('body.stock #careers-main #lead-in #secondary a').click(function(e){
				// UTC Investor Relations Button
				_gaq.push([ '_trackEvent', "contact_investors", "utcinv_link", "button", "" ]);
			});
		}
		
		/** CONTACT - NEWSLETTER **/
		if (the_body.className.indexOf('newsletter') > -1) {
			$('body.newsletter #contact-us a').click(function(e){
				// Left Sidebar Email links
				_gaq.push([ '_trackEvent', "contact_newsletter", "contact_email", $(this).attr('title') + "@" + $(this).attr('itemid'), "" ]);
			});
			$('body.newsletter #mc-contact form').submit(function(e){
				// description
				_gaq.push([ '_trackEvent', "contact_newsletter", "signup_submission", "", "" ]);
			});
		}
});
