var eventId = {
	'home': 2,
	'horsepower': 16,
	'balanced-performance': 21,
	'natural-design': 27,
	'spacious-cabin': 33,
	'welcoming-cockpit': 39,
	'exquisite-aesthetics': 45,
	'matchless-materials': 51,
	'natural-breeze': 57,
	'safety-shield': 63,
	'blind-spot-intervention': 69,
	'request-a-brochure': 4,
	'gallery': 14,
	'press': 12,
	'specs-options': 80,
	'final': 75
}

function initGui() {
	initGlobalElements();
	initTracking();
	
	if(jQuery('.gallery-container').length  > 0) initGallery();
	if(jQuery('#safety-1-text').length > 0) initSafetyShield();
	if(jQuery('#blindSpotDisclaimer').length > 0) initBlindSpot();
	if(jQuery('.specs-menu').length > 0) initSpecsPage();
}

function initGlobalElements() {
	//Next Arrow
	jQuery(".click-next-arrow").mouseover(function(){
		jQuery(".next-arrow-container-hover").css('display','block');
	}).mouseout(function(){
		jQuery(".next-arrow-container-hover").css('display','none');
	});
	
	//Back Arrow
	jQuery(".click-previous-arrow").mouseover(function(){
		jQuery(".previous-arrow-container-hover").css('display','block');
	}).mouseout(function(){
		jQuery(".previous-arrow-container-hover").css('display','none');
	});
	
	//Features Box
	jQuery("#features-btn").mouseover(function(){
		jQuery("#features-btn a").css('color','#DDDDDD');
		jQuery(".features-tab").css('display','block');
		jQuery(".features-nav").css('display','block');
		jQuery("#features-line").css('visibility','hidden');			
	}).mouseout(function(){
		jQuery("#features-btn a").css('color','#FFFFFF');
		jQuery(".features-tab").css('display','none');
		jQuery(".features-nav").css('display','none');
		jQuery("#features-line").css('visibility','visible');	
	});
	//Features Box Dark
	jQuery("#features-btn-dark").mouseover(function(){
		jQuery("#features-btn-dark a").css('color','#FFFFFF');
		jQuery(".features-tab").css('display','block');
		jQuery(".features-nav").css('display','block');
		jQuery("#features-line").css('visibility','hidden');			
	}).mouseout(function(){
		jQuery("#features-btn-dark a").css('color','#4C4C4C');
		jQuery(".features-tab").css('display','none');
		jQuery(".features-nav").css('display','none');
		jQuery("#features-line").css('visibility','visible');	
	});
	//Features Hidden Box
	jQuery(".features-nav").mouseover(function(){
		jQuery("#features-btn a").css('color','#DDDDDD');
		jQuery("#features-btn-dark a").css('color','#FFFFFF');
		jQuery(".features-tab").css('display','block');
		jQuery(".features-nav").css('display','block');
		jQuery("#features-line").css('visibility','hidden');			
	}).mouseout(function(){
		jQuery("#features-btn a").css('color','#FFFFFF');
		jQuery("#features-btn-dark a").css('color','#4C4C4C');
		jQuery(".features-tab").css('display','none');
		jQuery(".features-nav").css('display','none');
		jQuery("#features-line").css('visibility','visible');	
	});
	
	//Privacy Policy Box
	jQuery("#privacy-policy-btn").click(function(){
		jQuery("#privacy-policy-container").fadeIn("fast");
		jQuery("#blackout-container").css('display','block');
		jQuery("#blackout-container").css('opacity','0.6');
	});
	jQuery("#close-btn-privacy").click(function(){
		jQuery("#privacy-policy-container").fadeOut("fast");
		jQuery("#blackout-container").css('display','none');
	});	
}

//Microsite components
function initGallery() {
	var galleryThumbnails = jQuery('.photo-container .image-container a');
	galleryThumbnails.click(function(e){
		e.preventDefault();
		var thumbnailIndex = galleryThumbnails.index(this) + 1;
		jQuery("#gallery-popup-container").fadeIn("def");
		jQuery("#gallery-popup-container").removeClass();
		jQuery("#gallery-popup-container").addClass('largeimage-' + thumbnailIndex);
		jQuery("#blackout-container").css('display','block');
		jQuery("#blackout-container").css('opacity','0.6');
		crmEvent14({'num':thumbnailIndex, 'pageType':'HTML'});
	});
	//Photo Close Button
	jQuery("#close-btn").click(function(){
		jQuery("#gallery-popup-container").css('display','none');
		jQuery("#gallery-popup-container").removeClass();
		jQuery("#blackout-container").css('display','none');
	});
	//Wallpaper Download Tracking
	var galleryDownloadBtns = jQuery('.photo-container .links a');
	galleryDownloadBtns.click(function(e){
		var downloadLinkIndex = jQuery(this).attr('rel');
		crmEvent15({'num':downloadLinkIndex, 'pageType':'HTML'});
	});
}

function initSpecsPage() {
	//Main Menu Sliding
	jQuery('.specs-menu:eq(0)> h3:eq(0)').css('background-position','0 -31px');
	jQuery('.specs-menu:eq(0)> div:gt(0)').hide();
	jQuery('.specs-menu:eq(0)> h3').click(function() {
		jQuery(this).css('background-position','0 -31px').siblings().css('background-position','0 0');
		jQuery(this).next('div:hidden').slideDown('fast')
		.siblings('div:visible').slideUp('fast');
	});
	//Clicks on Anchors
	function moveUp(){
		var scrollToTop = document.getElementById("top");
		scrollToTop.scrollTop = 0;
	}
	jQuery(".specs-menu a:eq(0)").css('color','#FFFFFF');
	jQuery(".specs-menu a span:eq(0)").css('visibility','visible');
	var specsLink = jQuery('.specs-menu a');
	specsLink.click(function(e){
		e.preventDefault();
		//Hide All Top Bars
		jQuery("#showall-power, #showall-handling, #showall-exterior, #showall-interior, #showall-safety, #showall-dimensions, #showall-packages,#showall-individual").css('display','none');
		var specsLinkIndex = specsLink.index(this) + 1;
		jQuery(".specs-table table").css('display','none');
		moveUp();
		jQuery("#table"+ specsLinkIndex).css('display','block');
		jQuery(".specs-menu a").css('color','#7AA8FF');
		jQuery(this).css('color','#FFFFFF');
		jQuery(".specs-menu a span").css('visibility','hidden');
		jQuery(this).contents('span').css('visibility','visible');
		//Tracking
		var headingLinkTitle = jQuery(this).attr('rel');
		
		if(specsLinkIndex < 8){
			//tracks specs
			crmEvent80({'heading':headingLinkTitle, 'placement':'sub_nav', 'pageType':'HTML'});
		};
		if(specsLinkIndex >= 8){
			if(specsLinkIndex == 13){
				//tracks options
				crmEvent82({'heading':headingLinkTitle, 'placement':'sub_nav', 'pageType':'HTML'});
			} else{
				//tracks packages
				crmEvent81({'heading':headingLinkTitle, 'placement':'sub_nav', 'pageType':'HTML'});
			}
		};
	});
	//H3 Clicks
	//First
	jQuery('.specs-menu h3:eq(0)').click(function() {
		//Hide All Top Bars
		jQuery("#showall-power, #showall-handling, #showall-exterior, #showall-interior, #showall-safety, #showall-dimensions, #showall-packages,#showall-individual").css('display','none');
		jQuery(".specs-menu a span").css('visibility','hidden');
		jQuery(".specs-menu a").css('color','#7AA8FF');
		jQuery(".specs-menu a:eq(0)").css('color','#FFFFFF');
		jQuery(".specs-menu a span:eq(0)").css('visibility','visible');
		//table
		jQuery(".specs-table table").css('display','none');
		moveUp();
		jQuery("#table1").css('display','block');
		//tracking
		crmEvent80({'heading':'power', 'placement':'sub_nav', 'pageType':'HTML'});
	});
	//Second
	jQuery('.specs-menu h3:eq(1)').click(function() {
		//Hide All Top Bars
		jQuery("#showall-power, #showall-handling, #showall-exterior, #showall-interior, #showall-safety, #showall-dimensions, #showall-packages,#showall-individual").css('display','none');
		jQuery(".specs-menu a span").css('visibility','hidden');
		jQuery(".specs-menu a").css('color','#7AA8FF');
		jQuery(".specs-menu a:eq(7)").css('color','#FFFFFF');
		jQuery(".specs-menu a span:eq(7)").css('visibility','visible');
		//table
		jQuery(".specs-table table").css('display','none');
		moveUp();
		jQuery("#table8").css('display','block');
		//tracking
		crmEvent81({'heading':'premium_package', 'placement':'sub_nav', 'pageType':'HTML'});
	});
	//Specs Show All
	jQuery('.specs-menu a:eq(6)').click(function() {
		//Hide All Top Bars
		jQuery("#showall-power, #showall-handling, #showall-exterior, #showall-interior, #showall-safety, #showall-dimensions, #showall-packages,#showall-individual").css('display','none');
		//table
		jQuery(".specs-table table").css('display','none');
		moveUp();
		jQuery("#table1, #table2, #table3, #table4, #table5, #table6").css('display','block');
		//Show All SPEC Top Bars
		jQuery("#showall-power, #showall-handling, #showall-exterior, #showall-interior, #showall-safety, #showall-dimensions").css('display','block');
	});
	//Packages and Options Show All
	jQuery('.specs-menu a:eq(13)').click(function() {
		//Hide All Top Bars
		jQuery("#showall-power, #showall-handling, #showall-exterior, #showall-interior, #showall-safety, #showall-dimensions, #showall-packages,#showall-individual").css('display','none');
		//table
		jQuery(".specs-table table").css('display','none');
		moveUp();
		jQuery("#table8, #table9, #table10, #table11, #table12, #table13").css('display','block');
		//Show All SPEC Top Bars
		jQuery("#showall-packages, #showall-individual").css('display','block');
	});
	//Disclaimers
	jQuery('a.disclaimer-link').hover(function(e){
		var disclaimerContent = jQuery(this).contents('span').html();
		var linkPosition = jQuery(this).offset();

		jQuery('#disclaimer-container').html(disclaimerContent);
		jQuery("#disclaimer-container").css( { "left":linkPosition.left + "px", "top":linkPosition.top + 35 + "px" } );
		jQuery('#disclaimer-container').fadeIn("fast");
	}, function(){
		jQuery('#disclaimer-container').css('display','none');
	});
	//pop ups, stops # from triggering
	jQuery('a.disclaimer-link').click(function(e){
		e.preventDefault();
	});	
}

function initBlindSpot() {
	//Disclaimers
	//1
	jQuery("#blindSpotDisclaimer").click(function(){
		jQuery("#disclaimer-1-popup").fadeIn("fast");
		jQuery("#blackout-container").css('display','block');
		jQuery("#blackout-container").css('opacity','0.6');
	});
	jQuery("#close-1-btn").click(function(){
		jQuery("#disclaimer-1-popup").fadeOut("fast");
		jQuery("#blackout-container").css('display','none');
	});
}

function initSafetyShield() {
	//Safety Shield
	//Overview
	jQuery(".overview-btn").click(function(){
		jQuery(".safety-image-slide").css('background-position','0 -68px');
		jQuery("#overview-text").css('display','block');
		jQuery("#safety-1-text").css('display','none');
		jQuery("#safety-2-text").css('display','none');
		jQuery("#safety-3-text").css('display','none');
		jQuery("#safety-4-text").css('display','none');
		jQuery("#safety-5-text").css('display','none');
	});
	//Button One
	jQuery(".safety-1-btn").click(function(){
		jQuery(".safety-image-slide").css('background-position','0 -788px');
		jQuery("#overview-text").css('display','none');
		jQuery("#safety-1-text").css('display','block');
		jQuery("#safety-2-text").css('display','none');
		jQuery("#safety-3-text").css('display','none');
		jQuery("#safety-4-text").css('display','none');
		jQuery("#safety-5-text").css('display','none');
	});
	//Button Two
	jQuery(".safety-2-btn").click(function(){
		jQuery(".safety-image-slide").css('background-position','0 -1508px');
		jQuery("#overview-text").css('display','none');
		jQuery("#safety-1-text").css('display','none');
		jQuery("#safety-2-text").css('display','block');
		jQuery("#safety-3-text").css('display','none');
		jQuery("#safety-4-text").css('display','none');
		jQuery("#safety-5-text").css('display','none');
	});
	//Button Three
	jQuery(".safety-3-btn").click(function(){
		jQuery(".safety-image-slide").css('background-position','0 -2228px');
		jQuery("#overview-text").css('display','none');
		jQuery("#safety-1-text").css('display','none');
		jQuery("#safety-2-text").css('display','none');
		jQuery("#safety-3-text").css('display','block');
		jQuery("#safety-4-text").css('display','none');
		jQuery("#safety-5-text").css('display','none');
	});
	//Button Four
	jQuery(".safety-4-btn").click(function(){
		jQuery(".safety-image-slide").css('background-position','0 -2948px');
		jQuery("#overview-text").css('display','none');
		jQuery("#safety-1-text").css('display','none');
		jQuery("#safety-2-text").css('display','none');
		jQuery("#safety-3-text").css('display','none');
		jQuery("#safety-4-text").css('display','block');
		jQuery("#safety-5-text").css('display','none');
	});
	//Button Five
	jQuery(".safety-5-btn").click(function(){
		jQuery(".safety-image-slide").css('background-position','0 -3668px');
		jQuery("#overview-text").css('display','none');
		jQuery("#safety-1-text").css('display','none');
		jQuery("#safety-2-text").css('display','none');
		jQuery("#safety-3-text").css('display','none');
		jQuery("#safety-4-text").css('display','none');
		jQuery("#safety-5-text").css('display','block');
	});
	//Disclaimers
	//1
	jQuery("#disclaimer-1-btn").click(function(){
		jQuery("#disclaimer-1-popup").fadeIn("fast");
		jQuery("#blackout-container").css('display','block');
		jQuery("#blackout-container").css('opacity','0.6');
	});
	jQuery("#close-1-btn").click(function(){
		jQuery("#disclaimer-1-popup").fadeOut("fast");
		jQuery("#blackout-container").css('display','none');
	});
	//2
	jQuery("#disclaimer-2-btn").click(function(){
		jQuery("#disclaimer-2-popup").fadeIn("fast");
		jQuery("#blackout-container").css('display','block');
		jQuery("#blackout-container").css('opacity','0.6');
	});
	jQuery("#close-2-btn").click(function(){
		jQuery("#disclaimer-2-popup").fadeOut("fast");
		jQuery("#blackout-container").css('display','none');
	});
	//3
	jQuery("#disclaimer-3-btn").click(function(){
		jQuery("#disclaimer-3-popup").fadeIn("fast");
		jQuery("#blackout-container").css('display','block');
		jQuery("#blackout-container").css('opacity','0.6');
	});
	jQuery("#close-3-btn").click(function(){
		jQuery("#disclaimer-3-popup").fadeOut("fast");
		jQuery("#blackout-container").css('display','none');
	});
	//4
	jQuery("#disclaimer-4-btn").click(function(){
		jQuery("#disclaimer-4-popup").fadeIn("fast");
		jQuery("#blackout-container").css('display','block');
		jQuery("#blackout-container").css('opacity','0.6');
	});
	jQuery("#close-4-btn").click(function(){
		jQuery("#disclaimer-4-popup").fadeOut("fast");
		jQuery("#blackout-container").css('display','none');
	});
	//5
	jQuery("#disclaimer-5-btn").click(function(){
		jQuery("#disclaimer-5-popup").fadeIn("fast");
		jQuery("#blackout-container").css('display','block');
		jQuery("#blackout-container").css('opacity','0.6');
	});
	jQuery("#close-5-btn").click(function(){
		jQuery("#disclaimer-5-popup").fadeOut("fast");
		jQuery("#blackout-container").css('display','none');
	});
}

function trackHtmlPageLoad(urlHash) {
	try {
		if(eventId[urlHash] == '80'){
			eval('crmEvent'+eventId[urlHash]+'({"heading": "power", "placement": "page", "pageType": "HTML"});');	
	} 	else if(eventId[urlHash] == '14'){
			eval('crmEvent'+eventId[urlHash]+'({"num": "all", "pageType": "HTML"});');	
		} 
		else {
			eval('crmEvent'+eventId[urlHash]+'({"pageType": "HTML"});');
		}
	} catch(e) {}
}
