/***********************
* 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) {
//get the id of the clicked item         // insert code to be run when the composition is fully loaded here
         var headline;
         var headlinetxt = sym.getSymbol("styleMc").$("headlineTxt").css("pointer-events","none");
         var source;
         var sourcetxt = sym.getSymbol("styleMc").$("sourceTxt").css("pointer-events","none");
         var txt1
         var txt1txt = sym.$("txt1").css("pointer-events","none");
         var txt2;
         var txt2txt = sym.$("txt2").css("pointer-events","none");
         var txt14;
         var txt14txt = sym.$("txt14").css("pointer-events","none");

//AJAX retrieves data from xml source specified in url, maps xml variable to DOM object variable
           $.ajax({	
         	type: "GET",
         	url: "GN30198.xml",
         	dataType: "xml",
         	success: function(xml) {
					headline = $(xml).find('headline').text();
         		headlinetxt.html(headline);
         		source = $(xml).find('source').text();
         		sourcetxt.html(source);
         		txt1 = $(xml).find('txt1').text();
         		txt1txt.html(txt1);
         		txt2 = $(xml).find('txt2').text();
         		txt2txt.html(txt2);
         		txt14 = $(xml).find('txt14').text();
         		txt14txt.html(txt14);             
         		}
         	}); // END XML

var counter = 1; // SET COUNTER

// STOP ELEMENTS INTERACTING WITH MOUSE
	sym.$("handMc").css("pointer-events","none");

// MAKE ELEMENTS INVISIBLE
	sym.$("handMc").animate({opacity: 0}, 0);
	sym.$("car2").animate({opacity: 0}, 0);
	sym.$("car3").animate({opacity: 0}, 0);
	sym.getSymbol("btnBackMc").$("btnBack").fadeOut(0);
	sym.$("btnBackMc").fadeOut(0);
	sym.$("txt2").fadeOut(0);
	sym.$("sun").fadeOut(0);
	sym.getSymbol("btnNextMc").$("btnBack").fadeOut(0);

// MOVE HAND
	sym.$("handMc").delay(500).animate ({opacity:1, left:766, top:561}, 2000);

function hideDots() {
		var dot_arr = ["dot0","dot1","dot2","dot3","dot4","dot5","dot6"];
		$.each(dot_arr, function(index, value) {
		sym.$(value).fadeOut(0);
		});
		sym.$("dot"+counter).fadeIn(0);
}
	hideDots();	

function showcounters() {
		sym.$("car" + (counter - 1)).animate ({opacity:0, left:0, top:420, width:150, height:88}, 600, 'easeInOutCubic');
		sym.$("car" + (counter - 2)).animate ({opacity:0, left:0, top:420, width:150, height:88}, 600, 'easeInOutCubic');
		sym.$("car" + (counter - 3)).animate ({opacity:0, left:0, top:420, width:150, height:88}, 600, 'easeInOutCubic');
		sym.$("car" + (counter - 4)).animate ({opacity:0, left:0, top:420, width:150, height:88}, 600, 'easeInOutCubic');
		sym.$("car" + (counter - 5)).animate ({opacity:0, left:0, top:420, width:150, height:88}, 600, 'easeInOutCubic');
		sym.$("car" + (counter - 6)).animate ({opacity:0, left:0, top:420, width:150, height:88}, 600, 'easeInOutCubic');
		sym.$("car" + (counter - 7)).animate ({opacity:0, left:0, top:420, width:150, height:88}, 600, 'easeInOutCubic');

		sym.$("car" + (counter + 1)).animate ({opacity:0, left:650, top:420, width:150, height:88}, 600, 'easeInOutCubic');
		sym.$("car" + (counter + 2)).animate ({opacity:0, left:650, top:420, width:150, height:88}, 600, 'easeInOutCubic');
		sym.$("car" + (counter + 3)).animate ({opacity:0, left:650, top:420, width:150, height:88}, 600, 'easeInOutCubic');
		sym.$("car" + (counter + 4)).animate ({opacity:0, left:650, top:420, width:150, height:88}, 600, 'easeInOutCubic');
		sym.$("car" + (counter + 5)).animate ({opacity:0, left:650, top:420, width:150, height:88}, 600, 'easeInOutCubic');
		sym.$("car" + (counter + 6)).animate ({opacity:0, left:650, top:420, width:150, height:88}, 600, 'easeInOutCubic');
		sym.$("car" + (counter + 7)).animate ({opacity:0, left:650, top:420, width:150, height:88}, 600, 'easeInOutCubic');

		sym.$("car" + counter).animate ({opacity:1, left:0, top:38, width:800, height:470}, 800, 'easeInOutCubic');

		$.ajax({    
    		type: "GET",
    		url: "GN30198.xml",
    		dataType: "xml",
    		success: function(xml) { 
        		txt1 = $(xml).find("txt" + counter).text();
         	txt1txt.html(txt1);
         	txt2 = $(xml).find("txt" + (counter + 6)).text();
         	txt2txt.html(txt2);
				}
    		});

		sym.$("handMc").fadeOut(0);
		if (counter == 1) {
			sym.getSymbol("btnBackMc").$("btnBack").fadeOut(0);
			sym.$("btnBackMc").fadeOut(0);
			sym.$("txt2").fadeOut(0);
			sym.$("txt14").fadeIn(0);
			sym.$("sun").fadeOut(0);
		}else{
			sym.$("btnBackMc").fadeIn(0);
			sym.$("txt2").fadeIn(0);
			sym.$("sun").fadeIn(0);
			sym.$("txt14").fadeOut(0);
		}
		if (counter == 7) {
			sym.getSymbol("btnNextMc").$("btnBack").fadeOut(0);
			sym.$("btnNextMc").fadeOut(0);
		}else{
			sym.$("btnNextMc").fadeIn(0);
		}
		hideDots();
		resetmenu();
		sym.getSymbol("btnsMc").getSymbol("dot" + (counter - 1)).$("btnClick").fadeIn(0);
		}

// GLASS BUTTON
	Symbol.bindElementAction(compId, symbolName, "${_btnNextMc}", "click", function(sym, e) {
	counter++;
	showcounters();
	});
	Symbol.bindElementAction(compId, symbolName, "${_btnNextMc}", "mouseover", function(sym, e) {
	sym.$("handMc").fadeOut(0);
	sym.getSymbol("btnNextMc").$("btnBack").fadeIn(100);
	});
	Symbol.bindElementAction(compId, symbolName, "${_btnNextMc}", "mouseout", function(sym, e) {
	sym.getSymbol("btnNextMc").$("btnBack").fadeOut(100);
	});

	Symbol.bindElementAction(compId, symbolName, "${_btnBackMc}", "click", function(sym, e) {
	counter--;
	showcounters();
	});
	Symbol.bindElementAction(compId, symbolName, "${_btnBackMc}", "mouseover", function(sym, e) {
	sym.getSymbol("btnBackMc").$("btnBack").fadeIn(100);
	});
	Symbol.bindElementAction(compId, symbolName, "${_btnBackMc}", "mouseout", function(sym, e) {
	sym.getSymbol("btnBackMc").$("btnBack").fadeOut(100);
	});


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

         for (var h = 0; h < 7; h++){
         	 // Create an instance element of a symbol as a child of the given parent element
         	 var menuBtnSymbols = sym.getSymbol("btnsMc").getSymbol("dot" +h);
         	 //set the value of a Symbol variable
         	 menuBtnSymbols.setVariable("menuId", h);
         	 //push it into the array
         	 menuArray.push(menuBtnSymbols);
         }

         //a 'for each' loop through the newly populated array.
         $.each(menuArray, function( count, menuInTheArray ){
         	 //create jQuery reference to the item.
         	 var menuBtnItem = $(menuInTheArray); 
         	 //create a jQuery reference to the DIV element inside the symbol.
         	 var menuBtnElement = menuInTheArray.getSymbolElement();
         	 //now you can bind interactivity to the menu items' DIVs
         	 menuBtnElement.bind ("click", {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){
		var menuMenu_id = (e.data.menuId + 1); //get the id of the clicked item
		sym.getSymbol("btnsMc").getSymbol("dot" + (menuMenu_id - 1)).$("btnClick").fadeIn(0);
		counter = menuMenu_id;
		showcounters();
	}

	function menuShow (e){
         	var menuMenu_id = (e.data.menuId); //get the id of the over button
         	sym.$('handMc').hide();
				sym.getSymbol("btnsMc").getSymbol("dot" + menuMenu_id).$("btnOver").fadeIn(0);
	}
	function menuHide (e){
         	var menuMenu_id = (e.data.menuId); //get the id of the out button
				sym.getSymbol("btnsMc").getSymbol("dot" + menuMenu_id).$("btnOver").fadeOut(0);
	}

// MAKE MENU 0 VISIBLE
	sym.getSymbol("btnsMc").getSymbol("dot0").$("btnClick").fadeIn(0);





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


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

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

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

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

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

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

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

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

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