/***********************
* 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) {
	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 menuIcon0;
	var menuIcon0txt = sym.getSymbol("styleHead").getSymbol("menuBtn0").$("txt").css("pointer-events","none");
	var menuIcon1;
	var menuIcon1txt = sym.getSymbol("styleHead").getSymbol("menuBtn1").$("txt").css("pointer-events","none");
	var menuIcon2;
	var menuIcon2txt = sym.getSymbol("styleHead").getSymbol("menuBtn2").$("txt").css("pointer-events","none");
	var menuIcon3;
	var menuIcon3txt = sym.getSymbol("styleHead").getSymbol("menuBtn3").$("txt").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 menuTxt3;
	var menuTxt3txt = sym.getSymbol("styleHead").$("menuTxt3").css("pointer-events","none");
	
	//create array of text elements
	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").$("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("carTopMc").getSymbol("carTopPointersMc").$("txt6").css({"border-width":"1px","border-style":"solid","border-color":"rgba(255,255,255,1)","background-color":"rgba(50,50,50,1)"});
	txt[7] = sym.getSymbol("carTopMc").getSymbol("carTopPointersMc").$("txt7").css({"border-width":"1px","border-style":"solid","border-color":"rgba(255,255,255,1)","background-color":"rgba(50,50,50,1)"});
	txt[8] = sym.getSymbol("carTopMc").getSymbol("carTopPointersMc").$("txt8").css({"border-width":"1px","border-style":"solid","border-color":"rgba(255,255,255,1)","background-color":"rgba(50,50,50,1)"});
	txt[9] = sym.getSymbol("carTopMc").getSymbol("carTopPointersMc").$("txt9").css({"border-width":"1px","border-style":"solid","border-color":"rgba(255,255,255,1)","background-color":"rgba(50,50,50,1)"});
	txt[10] = sym.getSymbol("carTopMc").getSymbol("carTopPointersMc").$("txt10").css({"border-width":"1px","border-style":"solid","border-color":"rgba(255,255,255,1)","background-color":"rgba(50,50,50,1)"});
	txt[11] = sym.getSymbol("carTopMc").getSymbol("carTopPointersMc").$("txt11").css({"border-width":"1px","border-style":"solid","border-color":"rgba(255,255,255,1)","background-color":"rgba(50,50,50,1)"});
	txt[12] = sym.getSymbol("carTopMc").getSymbol("carTopPointersMc").$("txt12").css({"border-width":"1px","border-style":"solid","border-color":"rgba(255,255,255,1)","background-color":"rgba(50,50,50,1)"});
	txt[13] = sym.getSymbol("interiorMc").$("txt13").css({"background-color":"rgba(255,255,255,1)", "padding-right":"4px"});
	txt[14] = sym.$("txt14").css("pointer-events","none");
	txt[15] = sym.$("txt15").css("pointer-events","none");
	txt[16] = sym.$("txt16").css("pointer-events","none");
	txt[17] = sym.$("txt17").css("pointer-events","none");
	txt[18] = sym.$("txt18").css("pointer-events","none");
	txt[19] = sym.$("txt19").css("pointer-events","none");
	txt[20] = sym.$("txt20").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: "GN31458.xml",
		dataType: "xml",
		success: function(xml) {
			headline = $(xml).find('headline').text();
			headlinetxt.html(headline);
			stand = $(xml).find('stand').text();
			standtxt.html(stand);
			source = $(xml).find('source').text();
			sourcetxt.html(source);
			menuIcon0 = $(xml).find('menuIcon0').text();
			menuIcon0txt.html(menuIcon0);
			menuIcon1 = $(xml).find('menuIcon1').text();
			menuIcon1txt.html(menuIcon1);  
			menuIcon2 = $(xml).find('menuIcon2').text();
			menuIcon2txt.html(menuIcon2);
			menuIcon3 = $(xml).find('menuIcon3').text();
			menuIcon3txt.html(menuIcon3);
			menuTxt0 = $(xml).find('menuTxt0').text();
			menuTxt0txt.html(menuTxt0);  
			menuTxt1 = $(xml).find('menuTxt1').text();
			menuTxt1txt.html(menuTxt1);  
			menuTxt2 = $(xml).find('menuTxt2').text();
			menuTxt2txt.html(menuTxt2);
			menuTxt3 = $(xml).find('menuTxt3').text();
			menuTxt3txt.html(menuTxt3);
	
			//create array from xml, put it into array of text elements
			for (var i=0; i<21; i++){
			txtArr[i]=$(xml).find('txt'+i).text();
			txt[i].html(txtArr[i]);
			}
	
			//sym.getSymbol("carMc").getSymbol("carPointersMc").$("txt4").animate({left:760 - sym.getSymbol("carMc").getSymbol("carPointersMc").$("txt4").width()}, 0);
			sym.getSymbol("carMc").getSymbol("carPointersMc").$("txt5").animate ({left:773 - sym.getSymbol("carMc").getSymbol("carPointersMc").$("txt5").width()+5}, 0);
			sym.getSymbol("carTopMc").getSymbol("carTopPointersMc").$("txt8").animate ({left:171 - sym.getSymbol("carTopMc").getSymbol("carTopPointersMc").$("txt8").width()/2}, 0);
			sym.getSymbol("carTopMc").getSymbol("carTopPointersMc").$("txt11").animate ({top:168 - sym.getSymbol("carTopMc").getSymbol("carTopPointersMc").$("txt11").height()+10}, 0);
		}
	}); // END XML
	
	// START ANIMATION
	sym.$("interiorMc").stop().animate ({opacity:0}, 200);
	sym.$("videoPanel").stop().animate ({opacity:0}, 200);
	sym.getSymbol("carMc").$("carPointersMc").animate ({opacity:0}, 0);
	sym.getSymbol("carTopMc").$("carTopPointersMc").animate ({opacity:0}, 0);
	sym.$("carTopMc").animate ({left:800}, 0);
	sym.$("carTopMc").stop().animate ({opacity:0}, 0);
	
	var carIn = 0;
	
	function carStage1() {
				sym.$("carMc").stop().animate ({left:-2000}, 0);
				sym.getSymbol("carMc").$("brakesReflect").stop().animate ({left:800}, 0);
				sym.getSymbol("carMc").$("wheelFront").stop().animate ({left:913, rotate:360}, 0);
				sym.getSymbol("carMc").$("wheelFrontRef").stop().animate ({left:913, 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").$("wing").stop().animate ({left:1479, top:247}, 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}, 2000, 'easeOutCubic');
			sym.getSymbol("carMc").$("wheelFront").delay(500).animate ({left:113, rotate:-360}, 2000, 'easeOutCubic');
			sym.getSymbol("carMc").$("wheelFrontRef").delay(500).animate ({left:113, rotate:360}, 2000, 'easeOutCubic');
			sym.getSymbol("carMc").$("wheelRear").delay(500).animate ({left:606, rotate:-360}, 2000, 'easeOutCubic');
			sym.getSymbol("carMc").$("wheelRearRef").delay(500).animate ({left:606, rotate:360}, 2000, 'easeOutCubic');
			sym.getSymbol("carMc").$("car").delay(500).animate ({left:0}, 2000, 'easeOutCubic');
			sym.getSymbol("carMc").$("wing").delay(500).animate ({left:678, top:247}, 2000, 'easeOutCubic', function() {
			sym.getSymbol("carMc").$("wing").animate ({left:688, top:232}, 2000, 'easeOutCubic');
			sym.getSymbol("carMc").$("carPointersMc").stop().animate ({opacity:1}, 500);
			});
			sym.$("road").stop().animate ({opacity:1}, 500);
	}else{
			sym.getSymbol("carMc").$("carPointersMc").stop().animate ({opacity:0}, 200);
			sym.getSymbol("carMc").$("brakesReflect").stop().animate ({left:-800}, 600, 'easeInCubic');
			sym.getSymbol("carMc").$("wheelFront").stop().animate ({left:-682, rotate:-720}, 600, 'easeInCubic');
			sym.getSymbol("carMc").$("wheelFrontRef").stop().animate ({left:-682, rotate:720}, 600, 'easeInCubic');
			sym.getSymbol("carMc").$("wheelRear").stop().animate ({left:-189, rotate:-720}, 600, 'easeInCubic');
			sym.getSymbol("carMc").$("wheelRearRef").stop().animate ({left:-189, rotate:720}, 600, 'easeInCubic');
			sym.getSymbol("carMc").$("car").stop().animate ({left:-800}, 600, 'easeInCubic');
			sym.getSymbol("carMc").$("wing").stop().animate ({left:-105}, 600, 'easeInCubic', function() { carStage1(); });
			sym.$("road").stop().animate ({opacity:0}, 600);
	}
	}
	carStage();
	
	// CAR TOP
	var carTopIn = 0;
	
	function carTop() {
	if (carTopIn==0) {
		sym.$("carTopMc").stop().animate ({opacity:1}, 0);
		sym.$("carTopMc").stop().delay(500).animate ({left:0}, 800, 'easeOutCubic', function() {
		sym.getSymbol("carTopMc").$("carTopPointersMc").stop().animate ({opacity:1}, 500);
		});
	}else{
		sym.$("carTopMc").stop().animate ({left:-800}, 800, 'easeInCubic', function() {
			sym.$("carTopMc").stop().animate ({left:800}, 0);
			sym.$("carTopMc").stop().animate ({opacity:0}, 0);
		});
		sym.getSymbol("carTopMc").$("carTopPointersMc").stop().animate ({opacity:0}, 200);
	}
	}
	
	// MENU BUTTONS --------------------------------------------	
	menuArray = []; //the array that will hold references to the buttons.
	
	for (var h = 0; h < 4; h++){
		var menuBtnSymbols = sym.getSymbol("styleHead").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++){
			var resetmenu_arr = ["menuTxt0","menuTxt1","menuTxt2","menuTxt3"];
			$.each(resetmenu_arr, function(index, value) {
			sym.getSymbol("styleHead").$(value).fadeOut(0);
			});
         menuArray[h].$("btnClick").fadeOut(0);
         menuArray[h].$("btnOver").fadeOut(0);
		}
	}
	resetmenu();

	function menuBtnClick (e){
		resetmenu1()
		resetmenu();
		var menuMenu_id = (e.data.menuId); //get the id of the clicked item
		sym.getSymbol("styleHead").getSymbol("menuBtn" + menuMenu_id).$("btnClick").fadeIn(0);
		sym.getSymbol("styleHead").$("menuTxt" + menuMenu_id).fadeIn(0);
		if (menuMenu_id==0) {
			carIn = 0;
			carTopIn = 1;
			resetAll();
		}
		if (menuMenu_id==1) {
			carIn = 1;
			carTopIn = 0;
			resetAll();
		}
		if (menuMenu_id==2) {
			carIn = 1;
			carTopIn = 1;
			resetAll();
			sym.$("interiorMc").stop().fadeIn();
			sym.$("interiorMc").stop().delay(400).animate ({opacity:1}, 800);
		}
		if (menuMenu_id==3) {
			carIn = 1;
			carTopIn = 1;
			resetAll();
			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.$('handMc').hide();
				sym.getSymbol("styleHead").getSymbol("menuBtn" + menuMenu_id).$("btnOver").fadeIn(0);
				sym.getSymbol("styleHead").$("menuTxt" + menuMenu_id).fadeIn(0);
	}
	function menuHide (e){
         	var menuMenu_id = (e.data.menuId); //get the id of the out button
				sym.getSymbol("styleHead").getSymbol("menuBtn" + menuMenu_id).$("btnOver").fadeOut(0);
				sym.getSymbol("styleHead").$("menuTxt" + menuMenu_id).fadeOut(0);
	}
	function resetAll() {
			carStage();
			carTop();
			sym.$("road").delay(400).fadeOut(500);
			sym.$("interiorMc").animate ({opacity:0}, 400, function() { sym.$("interiorMc").fadeOut(); });
			sym.$("videoPanel").animate ({opacity:0}, 400, function() { sym.$("videoPanel").fadeOut(); });
			document.getElementById('vid1').pause();
	}
	//resetAll();

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

// Embed a movie: create text variable 
var vid = $("<video width='800' height='450'  id='vid1'>" +
  "<source src='media/spider.mp4' type='video/mp4' />" +
  "<source src='media/spider.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');

// ROTATE 
(function($){
 var _e = document.createElement("canvas").width
 $.fn.cssrotate = function(d) {  
    return this.css({
  '-moz-transform':'rotate('+d+'deg)',
  '-webkit-transform':'rotate('+d+'deg)',
  '-o-transform':'rotate('+d+'deg)',
  '-ms-transform':'rotate('+d+'deg)'
 }).prop("rotate", _e ? d : null)
 }; 
 var $_fx_step_default = $.fx.step._default;
 $.fx.step._default = function (fx) {
 if(fx.prop != "rotate")return $_fx_step_default(fx);
 if(typeof fx.elem.rotate == "undefined")fx.start = fx.elem.rotate = 0;
 $(fx.elem).cssrotate(fx.now)
 }; 
})(jQuery);

















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

	for (var k = 0; k < 5; k++){
		var menu1BtnSymbols = sym.getSymbol("carTopMc").getSymbol("carTopPointersMc").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 = ["txt8","txt9","txt10","txt11","txt12"];
			$.each(resetmenu1_arr, function(index, value) {
			sym.getSymbol("carTopMc").getSymbol("carTopPointersMc").$(value).fadeOut(0);
			});
         menu1Array[k].$("btnClick").fadeOut(0);
         menu1Array[k].$("btnOver").fadeOut(0);
		}
	}
	resetmenu1();

	var rndClicked = 5;

	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 = 5;
			//sym.getSymbol("carTopMc").getSymbol("carTopPointersMc").getSymbol("btn" + menu1menu1_id).$("btnClick").fadeIn(0);
			//sym.getSymbol("carTopMc").getSymbol("carTopPointersMc").$("txt" + (menu1menu1_id + 8)).fadeIn(0);
		}else{
			sym.getSymbol("carTopMc").getSymbol("carTopPointersMc").getSymbol("btn" + menu1menu1_id).$("btnClick").fadeIn(0);
			sym.getSymbol("carTopMc").getSymbol("carTopPointersMc").$("txt" + (menu1menu1_id + 8)).fadeIn(0);



		if (menu1menu1_id==0) {
			rndClicked = 0;
		}
		if (menu1menu1_id==1) {
			rndClicked = 1;
		}
		if (menu1menu1_id==2) {
			rndClicked = 2;
		}
		if (menu1menu1_id==3) {
			rndClicked = 3;
		}
		if (menu1menu1_id==4) {
			rndClicked = 4;
		}
		}
	}
	function menu1Show (e){
         	var menu1menu1_id = (e.data.menu1Id); //get the id of the over button
				sym.getSymbol("carTopMc").getSymbol("carTopPointersMc").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("carTopMc").getSymbol("carTopPointersMc").getSymbol("btn" + menu1menu1_id).$("btnOver").fadeOut(0);
	}

// MAKE menu1 0 VISIBLE
	sym.getSymbol("carTop").getSymbol("carTopPointersMc").getSymbol("btn0").$("btnClick").fadeIn(0);

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


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

   //=========================================================
   
   //Edge symbol: 'carMc'
   (function(symbolName) {   
   
      

      

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

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

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

   //=========================================================
   
   //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: 'pointersMc'
   (function(symbolName) {   
   
   })("pointersMc");
   //Edge symbol end:'pointersMc'

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

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

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

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

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

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