/***********************
* 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 clickEventType = ('ontouchstart' in document.documentElement ? "touchstart" : "click");
	
	var headline;
	var headlinetxt = sym.getSymbol("styleHead").$("headlineTxt").css("pointer-events","none");
	var source;
	var sourcetxt = sym.getSymbol("styleBase").$("sourceTxt").css("pointer-events","none");
	
	var txt=[];
	txt[0] = sym.$("txtBox").css({"pointer-events":"none", "background-color":"rgba(0,0,0,0.85)", "padding":"8px", "padding-bottom":"50px"});
	txt[1] = sym.$("txt1").css("pointer-events","none");
	txt[2] = sym.$("txt2").css("pointer-events","none");
	txt[3] = sym.$("txt3").css("pointer-events","none");
	txt[4] = sym.$("txt4").css("pointer-events","none");
	txt[5] = sym.$("txt5").css("pointer-events","none");
	txt[6] = sym.$("txt6").css("pointer-events","none");
	txt[7] = sym.$("txt7").css("pointer-events","none");
	txt[8] = sym.$("txt8").css("pointer-events","none");
	txt[9] = sym.$("txt9").css("pointer-events","none");
	txt[10] = sym.$("txt10").css("pointer-events","none");
	txt[11] = sym.$("txt11").css("pointer-events","none");
	txt[12] = sym.$("txt12").css("pointer-events","none");
	txt[13] = sym.$("txt13").css("pointer-events","none");
	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({	
		type: "GET",
		url: "GN32494.xml",
		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);
			source = $(xml).find('source').text();
			sourcetxt.html(source);
	
			for (var i=0; i<20; i++){
			txtArr[i]=$(xml).find('txt'+i).text();
			txt[i].html(txtArr[i]);
			}
	
			sym.$("txtBox").animate({top:560 - sym.$("txtBox").height()+10}, 0);
			sym.$("toggleBtn").animate({top: 560 - sym.$("txtBox").height()-20}, 0);
	
		}
	}); // END XML
	
	sym.getSymbol("toggleBtn").$("arrowUp").fadeOut(0);
	
	// MENU BUTTONS --------------------------------------------	
	menuArray = []; //the array that will hold references to the buttons.
	
	for (var h = 0; h < 18; h++){
		var menuBtnSymbols = sym.getSymbol("btnsMc").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 (clickEventType, {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);
			for (var k=0; k<18; k++){
				sym.getSymbol("mainImageMc").$("imageMain" + k).fadeOut(200);
			}
		}
	}
	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("btnsMc").getSymbol("menuBtn" + menuMenu_id).$("btnClick").fadeIn(0);
		sym.getSymbol("mainImageMc").$("imageMain" + (menuMenu_id)).fadeIn(700);

		sym.$("txtBox").empty();
		sym.$("txtBox").css('height','');
		sym.$("txtBox").css('height','auto');
		sym.$("txtBox").append(txtArr[menuMenu_id]);

		sym.$("txtBox").animate({top: 560 - sym.$("txtBox").height()+10}, 500, "easeOutCubic");
		sym.$("toggleBtn").animate({top: 560 - sym.$("txtBox").height()-20}, 500, "easeOutCubic");
		sym.getSymbol("toggleBtn").$("arrowDown").fadeIn(50);
		sym.getSymbol("toggleBtn").$("arrowUp").fadeOut(50);
		e.stopPropagation(); e.preventDefault();
	}
	function menuShow (e){
		var menuMenu_id = (e.data.menuId); //get the id of the over button
		sym.getSymbol("btnsMc").getSymbol("menuBtn"+menuMenu_id).$("btnOver").fadeIn();
		e.stopPropagation(); e.preventDefault();
	}
	function menuHide (e){
		var menuMenu_id = (e.data.menuId); //get the id of the out button
		sym.getSymbol("btnsMc").getSymbol("menuBtn"+menuMenu_id).$("btnOver").fadeOut();
		e.stopPropagation(); e.preventDefault();
	}

	for (var p=0; p<18; p++){
		sym.getSymbol("btnsMc").getSymbol("menuBtn"+p).$("btnClick").attr("src", "images/imageClik" + p + ".jpg");
		sym.getSymbol("btnsMc").getSymbol("menuBtn"+p).$("btnClick").fadeOut();
	}
	for (var k=0; k<18; k++){
		sym.getSymbol("btnsMc").getSymbol("menuBtn"+k).$("btnOver").attr("src", "images/imageClik" + k + ".jpg");
		sym.getSymbol("btnsMc").getSymbol("menuBtn"+k).$("btnOver").fadeOut();
	}
	for (var v=0; v<18; v++){
		sym.getSymbol("btnsMc").getSymbol("menuBtn"+v).$("btnOut").attr("src", "images/imageOut" + v + ".jpg");
	}

	sym.getSymbol("btnsMc").getSymbol("menuBtn0").$("btnClick").fadeIn(0);
	sym.getSymbol("mainImageMc").$("imageMain0").fadeIn(0);

// TOGGLE BUTTON
sym.$("toggleBtn").on(clickEventType, function(e){
	if (sym.getSymbol("toggleBtn").$("arrowDown").is(":visible") ) { 
		sym.getSymbol("toggleBtn").$("arrowDown").fadeOut(50);
		sym.getSymbol("toggleBtn").$("arrowUp").fadeIn(50);
		sym.$("txtBox").animate({top: 585}, 500, "easeOutCubic");
		sym.$("toggleBtn").animate({top: 555}, 495, "easeOutCubic");
	}else{
		sym.getSymbol("toggleBtn").$("arrowDown").fadeIn(50);
		sym.getSymbol("toggleBtn").$("arrowUp").fadeOut(50);
		sym.$("txtBox").animate({top: 560 - sym.$("txtBox").height()+10}, 500, "easeOutCubic");
		sym.$("toggleBtn").animate({top: 560 - sym.$("txtBox").height()-20}, 500, "easeOutCubic");
	}
	e.stopPropagation(); e.preventDefault();
}); 

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

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

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

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

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

   //=========================================================
   
   //Edge symbol: 'Down-level'
   (function(symbolName) {   
   
   })("Down-level");
   //Edge symbol end:'Down-level'

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