/***********************
* Adobe Edge Composition Actions
*
* Edit this file with caution, being careful to preserve 
* function signatures and comments starting with 'Edge' to maintain the 
* ability to interact with these actions from within Adobe Edge
*
***********************/
(function($, Edge, compId){
var Composition = Edge.Composition, Symbol = Edge.Symbol; // aliases for commonly used Edge classes

   //Edge symbol: 'stage'
   (function(symbolName) {
      
      
      Symbol.bindElementAction(compId, symbolName, "document", "compositionReady", function(sym, e) {
	for (var b=0;b<3; b++){
		sym.getSymbol("menuBtnsMc").getSymbol("menuBtn"+b).$("menuIcon").attr("src", "images/menuIcon" + b + ".png");
	}
	var btnNo = 0;
	
	var xmlNo = "GN31852.xml";
	
	var headline;
	var headlinetxt = sym.getSymbol("styleHead").$("headlineTxt").css("pointer-events","none");
	var stand;
	var standtxt = sym.getSymbol("styleHead").$("standTxt").css("pointer-events","none");
	var source;
	var sourcetxt = sym.getSymbol("styleBase").$("sourceTxt").css("pointer-events","none");
	var menuTxt0;
	var menuTxt0txt = sym.getSymbol("styleHead").$("menuTxt0").css("pointer-events","none");
	var menuTxt1;
	var menuTxt1txt = sym.getSymbol("styleHead").$("menuTxt1").css("pointer-events","none");
	var menuTxt2;
	var menuTxt2txt = sym.getSymbol("styleHead").$("menuTxt2").css("pointer-events","none");
	
	var txt=[];
	txt[0] = sym.getSymbol("carMc").getSymbol("carPointersMc").$("txt0").css("pointer-events","none");
	txt[1] = sym.getSymbol("carMc").getSymbol("carPointersMc").$("txt1").css("pointer-events","none");
	txt[2] = sym.getSymbol("carMc").getSymbol("carPointersMc").getSymbol("stableMc").$("txt2").css("pointer-events","none");
	txt[3] = sym.getSymbol("carMc").getSymbol("carPointersMc").$("txt3").css("pointer-events","none");
	txt[4] = sym.getSymbol("carMc").getSymbol("carPointersMc").$("txt4").css("pointer-events","none");
	txt[5] = sym.getSymbol("carMc").getSymbol("carPointersMc").$("txt5").css("pointer-events","none");
	txt[6] = sym.getSymbol("carMc").getSymbol("carPointersMc").$("txt6").css("pointer-events","none");
	txt[7] = sym.getSymbol("carMc").getSymbol("carPointersMc").$("txt7").css("pointer-events","none");
	txt[8] = sym.getSymbol("carMc").getSymbol("carPointersMc").$("txt8").css("pointer-events","none");
	txt[9] = sym.getSymbol("carMc").getSymbol("carPointersMc").getSymbol("stableMc").$("txt9").css("pointer-events","none");
	txt[10] = sym.getSymbol("carMc").getSymbol("carPointersMc").getSymbol("stableMc").$("txt10").css("pointer-events","none");
	txt[11] = sym.getSymbol("carMc").getSymbol("carPointersMc").getSymbol("stableMc").$("txt11").css("pointer-events","none");
	txt[12] = sym.getSymbol("carMc").getSymbol("carPointersMc").getSymbol("stableMc").$("txt12").css("pointer-events","none");
	txt[13] = sym.getSymbol("carMc").getSymbol("carPointersMc").getSymbol("stableMc").$("txt13").css("pointer-events","none");
	txt[14] = sym.getSymbol("interiorMc").$("txt14").css("pointer-events","none");
	txt[15] = sym.getSymbol("interiorMc").$("txt15").css("pointer-events","none");
	txt[16] = sym.getSymbol("interiorMc").$("txt16").css("pointer-events","none");
	txt[17] = sym.getSymbol("carMc").getSymbol("carPointersMc").$("txt17").css("pointer-events","none");
	var txtArr=[];
	
	//AJAX retrieves data from xml source specified in url, maps xml variable to DOM object variable
	$.ajax({	
		type: "GET",
		url: xmlNo,
		dataType: "xml",
		success: function(xml) {
			custonCol = $(xml).find('customColour').text();
			sym.getSymbol("styleHead").$("headerBox").css("background-color",custonCol);
			headline = $(xml).find('headline').text();
			headlinetxt.html(headline);
			stand = $(xml).find('stand').text();
			standtxt.html(stand);
			source = $(xml).find('source').text();
			sourcetxt.html(source);
			menuTxt0 = $(xml).find('menuTxt0').text();
			menuTxt0txt.html(menuTxt0);  
			menuTxt1 = $(xml).find('menuTxt1').text();
			menuTxt1txt.html(menuTxt1);  
			menuTxt2 = $(xml).find('menuTxt2').text();
			menuTxt2txt.html(menuTxt2);
	
			//create array from xml, put it into array of text elements
			for (var i=0; i<18; i++){
			txtArr[i]=$(xml).find('txt'+i).text();
			txt[i].html(txtArr[i]);
			}
	
			sym.getSymbol("carMc").getSymbol("carPointersMc").$("txt1").animate({top:216 - sym.getSymbol("carMc").getSymbol("carPointersMc").$("txt1").height()+15}, 0);
			sym.getSymbol("carMc").getSymbol("carPointersMc").$("txt7").animate({left:490 - sym.getSymbol("carMc").getSymbol("carPointersMc").$("txt7").width()+15}, 0);
			//sym.getSymbol("carMc").getSymbol("carPointersMc").$("txt2").animate({top:157 - sym.getSymbol("carMc").getSymbol("carPointersMc").$("txt2").height()+15}, 0);
	
		}
	}); // END XML
	
	// START ANIMATION
	sym.$("interiorMc").stop().fadeOut(0);
	sym.$("videoPanel").stop().animate ({opacity:0}, 200);
	//sym.$("videoPanel").fadeOut(0);
	//sym.getSymbol("carMc").$("carPointersMc").animate ({opacity:0}, 0);
	
	var carIn = 0;
	$.fx.speeds.slow = 1000; 
	
	function carStage1() {
				sym.$("carMc").stop().animate ({left:-2000}, 0);
				sym.getSymbol("carMc").$("wheelFront").stop().animate ({left:928, rotate:-360}, 0);
				sym.getSymbol("carMc").$("brakesReflect").stop().animate ({left:800}, 0);
				sym.getSymbol("carMc").$("wheelFrontRef").stop().animate ({left:928, rotate:-360}, 0);
				sym.getSymbol("carMc").$("wheelRear").stop().animate ({left:1406, rotate:360}, 0);
				sym.getSymbol("carMc").$("wheelRearRef").stop().animate ({left:1406, rotate:-360}, 0);
				sym.getSymbol("carMc").$("car").stop().animate ({left:800}, 0);
				sym.getSymbol("carMc").$("carPointersMc").stop().animate ({opacity:0}, 0);
				sym.$("road").stop().animate ({opacity:0}, 0);
	}
	
	function carStage() {
	if (carIn==0) {
		sym.$("carMc").stop().animate ({left:0}, 0);
		sym.getSymbol("carMc").$("brakesReflect").delay(500).animate ({left:0}, 'slow');
		sym.getSymbol("carMc").$("wheelFront").delay(500).animate({ rotate:360, left:128 }, {
			step: function(now,fx) {
			$(this).css('-webkit-transform','rotate('+now+'deg)'); 
			$(this).css('-moz-transform','rotate('+now+'deg)');
			$(this).css('transform','rotate('+now+'deg)');
			},duration:'slow', easing:'swing'});
		sym.getSymbol("carMc").$("wheelFrontRef").delay(500).animate({ rotate:360, left:128 }, {
			step: function(now,fx) {
			$(this).css('-webkit-transform','rotate('+now+'deg)'); 
			$(this).css('-moz-transform','rotate('+now+'deg)');
			$(this).css('transform','rotate('+now+'deg)');
			},duration:'slow'});
		sym.getSymbol("carMc").$("wheelRear").delay(500).animate({ rotate:360, left:602 }, {
			step: function(now,fx) {
			$(this).css('-webkit-transform','rotate('+now+'deg)'); 
			$(this).css('-moz-transform','rotate('+now+'deg)');
			$(this).css('transform','rotate('+now+'deg)');
			},duration:'slow'});
		sym.getSymbol("carMc").$("wheelRearRef").delay(500).animate({ rotate:360, left:602 }, {
			step: function(now,fx) {
			$(this).css('-webkit-transform','rotate('+now+'deg)'); 
			$(this).css('-moz-transform','rotate('+now+'deg)');
			$(this).css('transform','rotate('+now+'deg)');
			},duration:'slow'});
			sym.getSymbol("carMc").$("car").delay(500).animate ({left:0}, 'slow');
			sym.getSymbol("carMc").$("carPointersMc").stop().delay(2000).animate ({opacity:1}, 500);
			sym.getSymbol("carMc").$("roadTop").stop().animate ({opacity:1}, 200);
	}else{
			sym.getSymbol("carMc").$("carPointersMc").stop().animate ({opacity:0}, 300);
			sym.getSymbol("carMc").$("brakesReflect").stop().animate ({left:-1800}, 'slow');
			sym.getSymbol("carMc").$("wheelFront").stop().animate ({ rotate:720, left:-1682 }, {
				step: function(now,fx) {
				$(this).css('-webkit-transform','rotate('+now+'deg)'); 
				$(this).css('-moz-transform','rotate('+now+'deg)');
				$(this).css('transform','rotate('+now+'deg)');
				},duration:'slow'});
			sym.getSymbol("carMc").$("wheelFrontRef").stop().animate ({ rotate:720, left:-1682 }, {
				step: function(now,fx) {
				$(this).css('-webkit-transform','rotate('+now+'deg)'); 
				$(this).css('-moz-transform','rotate('+now+'deg)');
				$(this).css('transform','rotate('+now+'deg)');
				},duration:'slow'});
			sym.getSymbol("carMc").$("wheelRear").stop().animate ({ rotate:720, left:-1200 }, {
				step: function(now,fx) {
				$(this).css('-webkit-transform','rotate('+now+'deg)'); 
				$(this).css('-moz-transform','rotate('+now+'deg)');
				$(this).css('transform','rotate('+now+'deg)');
				},duration:'slow'});
			sym.getSymbol("carMc").$("wheelRearRef").stop().animate ({ rotate:720, left:-1200 }, {
				step: function(now,fx) {
				$(this).css('-webkit-transform','rotate('+now+'deg)'); 
				$(this).css('-moz-transform','rotate('+now+'deg)');
				$(this).css('transform','rotate('+now+'deg)');
				},duration:'slow'});
			sym.getSymbol("carMc").$("car").stop().animate ({left:-1800}, 'slow', function() { carStage1(); });
			sym.getSymbol("carMc").$("roadTop").stop().animate ({opacity:0}, 400);
	}
	}
	carStage();
	
	// MENU BUTTONS --------------------------------------------	
	menuArray = []; //the array that will hold references to the buttons.
	
	for (var h = 0; h < 3; h++){
		var menuBtnSymbols = sym.getSymbol("menuBtnsMc").getSymbol("menuBtn" +h); // Create an instance element of a symbol as a child of the given parent element
		menuBtnSymbols.setVariable("menuId", h); //set the value of a Symbol variable
		menuArray.push(menuBtnSymbols); //push it into the array
	}
	
	$.each(menuArray, function( count, menuInTheArray ){ //a 'for each' loop through the newly populated array
		var menuBtnItem = $(menuInTheArray); //create jQuery reference to the item
		var menuBtnElement = menuInTheArray.getSymbolElement(); //create a jQuery reference to the DIV element inside the symbol
		menuBtnElement.bind ("click", {menuId:count}, menuBtnClick);
		menuBtnElement.bind ("touchstart", {menuId:count}, menuBtnClick);
		menuBtnElement.bind ("mouseover", {menuId:count}, menuShow);
		menuBtnElement.bind ("mouseout", {menuId:count}, menuHide);
	})
	
	function resetmenu(){
		for (var h=0; h<menuArray.length; h++){
         menuArray[h].$("btnClick").fadeOut(0);
         menuArray[h].$("btnOver").fadeOut(0);
		}
	}
	resetmenu();

	function menuBtnClick (e){
		resetmenu(); //set them all back to normal state
		var menuMenu_id = (e.data.menuId); //get the id of the clicked item
		sym.getSymbol("menuBtnsMc").getSymbol("menuBtn" + menuMenu_id).$("btnClick").fadeIn(0);
		btnNo = menuMenu_id;
		menutxtLoad();
		sym.getSymbol("styleHead").$("standTxt").fadeIn(250)
		if (menuMenu_id==0) {
			sym.$("interiorMc").stop().fadeOut();
			carIn = 0;
			carStage();
			sym.$("videoPanel").animate ({opacity:0}, 400, function() { sym.$("videoPanel").fadeOut(); });
			document.getElementById('vid1').pause();
		}
		if (menuMenu_id==1) {
			sym.$("interiorMc").stop().fadeIn(500);
			carIn = 1;
			carStage();
			sym.$("videoPanel").animate ({opacity:0}, 400, function() { sym.$("videoPanel").fadeOut(); });
			document.getElementById('vid1').pause();
		}
		if (menuMenu_id==2) {
			sym.getSymbol("styleHead").$("standTxt").stop().fadeOut(250)
			sym.$("interiorMc").stop().fadeOut(500);
			carIn = 1;
			carStage();
			sym.$("videoPanel").stop().fadeIn();
			sym.$("videoPanel").stop().delay(400).animate ({opacity:1}, 800);
			document.getElementById('vid1').play(0);
		}
	}

	function menuShow (e){
		var menuMenu_id = (e.data.menuId); //get the id of the over button
		sym.getSymbol("menuBtnsMc").getSymbol("menuBtn" + menuMenu_id).$("btnOver").fadeIn(0);
		btnNo = menuMenu_id;
		menutxtLoad();
	}
	function menuHide (e){
		var menuMenu_id = (e.data.menuId); //get the id of the out button
		sym.getSymbol("menuBtnsMc").getSymbol("menuBtn" + menuMenu_id).$("btnOver").fadeOut(0);
		sym.getSymbol("menuBtnsMc").$("menuTxt").empty();
	}

// MAKE MENU 0 VISIBLE
	sym.getSymbol("menuBtnsMc").getSymbol("menuBtn0").$("btnClick").fadeIn(0);

// LOAD MENU TXT
	function menutxtLoad() {
		sym.getSymbol("menuBtnsMc").$("menuTxt").empty();
		if (btnNo==0) {
			sym.getSymbol("menuBtnsMc").$("menuTxt").append(menuTxt0);
		}
		if (btnNo==1) {
			sym.getSymbol("menuBtnsMc").$("menuTxt").append(menuTxt1);
		}
		if (btnNo==2) {
			sym.getSymbol("menuBtnsMc").$("menuTxt").append(menuTxt2);
		}
	}

// Embed a movie: create text variable 
var vid = $("<video width='800' height='450'  id='vid1'>" +
  "<source src='video/huracan.mp4' type='video/mp4' />" +
  "<source src='video/huracan.ogg' type='video/ogg' />" +
  "This browser is not compatible with HTML 5" +
"</video>");

sym.getSymbol("videoPanel").$("vidHolder").append(vid);

//vid.attr('autoplay','autoplay');
vid.attr('preload','auto');

	// menu1 BUTTONS --------------------------------------------	
	menu1Array = []; //the array that will hold references to the buttons. 

	for (var k = 0; k < 3; k++){
		var menu1BtnSymbols = sym.getSymbol("carMc").getSymbol("carPointersMc").getSymbol("btn" +k); // Create an instance element of a symbol as a child of the given parent element
		menu1BtnSymbols.setVariable("menu1Id", k); //set the value of a Symbol variable
		menu1Array.push(menu1BtnSymbols); //push it into the array
	}

	$.each(menu1Array, function( count, menu1InTheArray ){ //a 'for each' loop through the newly populated array
		var menu1BtnItem = $(menu1InTheArray); //create jQuery reference to the item
		var menu1BtnElement = menu1InTheArray.getSymbolElement(); //create a jQuery reference to the DIV element inside the symbol
		menu1BtnElement.bind ("click", {menu1Id:count}, menu1BtnClick);
		menu1BtnElement.bind ("touchstart", {menu1Id:count}, menu1BtnClick);
		menu1BtnElement.bind ("mouseover", {menu1Id:count}, menu1Show);
		menu1BtnElement.bind ("mouseout", {menu1Id:count}, menu1Hide);
	})

	function resetmenu1(){
		for (var k=0; k<menu1Array.length; k++){
			var resetmenu1_arr = ["stableMc","txt3","txt4","txt5","txt17"];
			$.each(resetmenu1_arr, function(index, value) {
			sym.getSymbol("carMc").getSymbol("carPointersMc").$(value).animate ({opacity:0}, 0);
			});
         menu1Array[k].$("btnClick").fadeOut(0);
         menu1Array[k].$("btnOver").fadeOut(0);
         sym.getSymbol("carMc").getSymbol("carPointersMc").$("btn2").fadeIn(0);//May 27
		}
	}
	resetmenu1();

	var rndClicked = 3;

	function menu1BtnClick (e){
		resetmenu1(); //set them all back to normal state
		var menu1menu1_id = (e.data.menu1Id); //get the id of the clicked item

		if (rndClicked == menu1menu1_id) {
			rndClicked = 3;

		}else{
			sym.getSymbol("carMc").getSymbol("carPointersMc").getSymbol("btn" + menu1menu1_id).$("btnClick").fadeIn(0);

		if (menu1menu1_id==0) {
			rndClicked = 0;
			sym.getSymbol("carMc").getSymbol("carPointersMc").$("stableMc").stop().animate ({opacity:1}, 400);
			sym.getSymbol("carMc").getSymbol("carPointersMc").$("txt3").stop().animate ({opacity:0}, 400);
			sym.getSymbol("carMc").getSymbol("carPointersMc").$("txt4").stop().animate ({opacity:0}, 400);
			sym.getSymbol("carMc").getSymbol("carPointersMc").$("txt5").stop().animate ({opacity:0}, 400);
			sym.getSymbol("carMc").getSymbol("carPointersMc").$("btn2").fadeOut(400);//May 27
		}
		if (menu1menu1_id==1) {
			rndClicked = 1;
			sym.getSymbol("carMc").getSymbol("carPointersMc").$("stableMc").stop().animate ({opacity:0}, 400);
			sym.getSymbol("carMc").getSymbol("carPointersMc").$("txt3").stop().animate ({opacity:1}, 400);
			sym.getSymbol("carMc").getSymbol("carPointersMc").$("txt4").stop().animate ({opacity:1}, 400);
			sym.getSymbol("carMc").getSymbol("carPointersMc").$("txt5").stop().animate ({opacity:1}, 400);
		}
		if (menu1menu1_id==2) {
			rndClicked = 2;
			sym.getSymbol("carMc").getSymbol("carPointersMc").$("stableMc").stop().animate ({opacity:0}, 400);
			sym.getSymbol("carMc").getSymbol("carPointersMc").$("txt17").stop().animate ({opacity:1}, 400);
		}
		}
	}
	function menu1Show (e){
         	var menu1menu1_id = (e.data.menu1Id); //get the id of the over button
				sym.getSymbol("carMc").getSymbol("carPointersMc").getSymbol("btn" + menu1menu1_id).$("btnOver").fadeIn(0);
	}
	function menu1Hide (e){
         	var menu1menu1_id = (e.data.menu1Id); //get the id of the out button
				sym.getSymbol("carMc").getSymbol("carPointersMc").getSymbol("btn" + menu1menu1_id).$("btnOver").fadeOut(0);
	}

// MAKE menu1 0 VISIBLE
	sym.getSymbol("carMc").getSymbol("carPointersMc").$("txt3").stop().animate ({opacity:1}, 400);
	sym.getSymbol("carMc").getSymbol("carPointersMc").$("txt4").stop().animate ({opacity:1}, 400);
	sym.getSymbol("carMc").getSymbol("carPointersMc").$("txt5").stop().animate ({opacity:1}, 400);
	sym.getSymbol("carMc").getSymbol("carPointersMc").getSymbol("btn1").$("btnClick").fadeIn(0);


	sym.getSymbol("videoPanel").$("btnFront").on('touchstart click', function(e){
	e.stopPropagation(); e.preventDefault();
		sym.getSymbol("videoPanel").$("carFront").fadeIn(500);
	});
	sym.getSymbol("videoPanel").$("btnBack").on('touchstart click', function(e){
	e.stopPropagation(); e.preventDefault();
		sym.getSymbol("videoPanel").$("carFront").fadeOut(500);
	});

         	});//Edge binding end	
		
		// VIDEO BTN 1 =========================================================
         	
			
         	
         		
         	
			
			
         	// VIDEO BTN 2 =========================================================
         	
         	
         	
         		
         	
         	


   })("stage");
   //Edge symbol end:'stage'

   //=========================================================
   
   //Edge symbol: 'StyleBase'
   (function(symbolName) {   
   
   })("StyleBase");
   //Edge symbol end:'StyleBase'

   //=========================================================
   
   //Edge symbol: 'styleHead_1'
   (function(symbolName) {   
   
   })("styleHead");
   //Edge symbol end:'styleHead'

   //=========================================================
   
   //Edge symbol: 'menuBtn_2'
   (function(symbolName) {   
   
   })("menuBtn");
   //Edge symbol end:'menuBtn'

   //=========================================================
   
   //Edge symbol: 'Preloader'
   (function(symbolName) {   
   
   })("Preloader");
   //Edge symbol end:'Preloader'

   //=========================================================
   
   //Edge symbol: 'menuBtnsMc'
   (function(symbolName) {   
   
   })("menuBtnsMc");
   //Edge symbol end:'menuBtnsMc'

   //=========================================================
   
   //Edge symbol: 'videoPanel'
   (function(symbolName) {   
   
   })("videoPanel");
   //Edge symbol end:'videoPanel'

   //=========================================================
   
   //Edge symbol: 'interiorMc'
   (function(symbolName) {   
   
   })("interiorMc");
   //Edge symbol end:'interiorMc'

   //=========================================================
   
   //Edge symbol: 'carMc'
   (function(symbolName) {   
   
   })("carMc");
   //Edge symbol end:'carMc'

   //=========================================================
   
   //Edge symbol: 'pointersMc'
   (function(symbolName) {   
   
   })("pointersMc");
   //Edge symbol end:'pointersMc'

   //=========================================================
   
   //Edge symbol: 'stableMc'
   (function(symbolName) {   
   
   })("stableMc");
   //Edge symbol end:'stableMc'

   //=========================================================
   
   //Edge symbol: 'plusMinusBtn'
   (function(symbolName) {   
   
   })("plusMinusBtn");
   //Edge symbol end:'plusMinusBtn'

   //=========================================================
   
   //Edge symbol: 'grillMc'
   (function(symbolName) {   
   
   })("grillMc");
   //Edge symbol end:'grillMc'

})(jQuery, AdobeEdge, "GraphicNews31852");