/***********************
* 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 source;
	var sourcetxt = sym.getSymbol("styleBase").$("sourceTxt").css("pointer-events","none");
	
	//create array of text elements
	var txt=[];
	txt[0] = sym.$("txt0").css("pointer-events","none");
	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");
	txt[21] = sym.$("txt21").css("pointer-events","none");
	txt[22] = sym.$("txt22").css("pointer-events","none");
	txt[23] = sym.$("txt23").css("pointer-events","none");
	txt[24] = sym.getSymbol("courseMc").$("txt24").css("pointer-events","none");
	txt[25] = sym.getSymbol("courseMc").$("txt25").css("pointer-events","none");
	txt[26] = sym.$("txt26").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: "GN31065.xml",
		dataType: "xml",
		success: function(xml) {
			headline = $(xml).find('headline').text();
			headlinetxt.html(headline);
			source = $(xml).find('source').text();
			sourcetxt.html(source);
	
			//create array from xml, put it into array of text elements
			for (var i=0; i<27; i++){
			txtArr[i]=$(xml).find('txt'+i).text();
			txt[i].html(txtArr[i]);
			}
	
			//sym.getSymbol("SYMBOL").$("txt").animate({top:yNUMBER - sym.getSymbol("SYMBOL").$("txt").height()+10}, 200);
	
		}
	}); // END XML

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

   //=========================================================
   
   //Edge symbol: 'TimelineController'
   (function(symbolName) {   
   
      Symbol.bindSymbolAction(compId, symbolName, "creationComplete", function(sym, e) {
         // flag of use keyboard event.
         
         var useKeyBoardEvent = true;

         // key code of right/left key

         var KEY_RIGHT = 39;

         var KEY_LEFT =  37;

         // params

         var power = 1.5;

         var declineRate = 0.5;

         var speedWidth = 30;

         
         // try to hide the location bar at Safari,if need, comment out it. 

         // setTimeout(function() { window.scrollTo(0, 0); }, 250);

         
         var fps = 60;

         var interval = (1000/fps)|0;

         var speed = 0;

         var isKeyPress = false, isMousePress = false;

         
         var centerX,target,v;

         
         if(useKeyBoardEvent)$(window).bind("keydown",onStartControll).bind("keyup",onStopControll);  

         
         var el = $(sym.getSymbolElement());

         el.mousedown(onStartControll)

           .mouseup(onStopControll)

           .mouseout(onStopControll)

           .mousemove(onMouseMove)

           .bind("touchstart",onStartControll)

           .bind("touchmove",onMouseMove)

           .bind("touchend",onStopControll);

         
         function onStartControll(evt){
         
           evt.preventDefault();

           target = sym.getParentSymbol();

           centerX = el.offset().left+el.width()/2;

           if(evt.type=="keydown" && isKeyPress===false){

             speed = 

               (evt.which==KEY_RIGHT)*interval*power

                  + (evt.which==KEY_LEFT)*interval*-1*power;

             speed|=0;

             isKeyPress = true;
           }else if(evt.type=="mousedown" || evt.type=="touchstart"){

             isMousePress = true;
           }

           if(v===undefined)v=setInterval(onControll,interval);
         }

         function onStopControll(evt){
     
           if(evt.type=="keyup"){

             isKeyPress = false;
           }else{

             isMousePress = false;
           }
         }

         function onControll(){

           if(isKeyPress===false && isMousePress===false){

             speed = (speed*declineRate)|0;

             if(-1<speed && speed<1){

               clearInterval(v);

               v = undefined;

             }

           }

           var n = target.getPosition()+speed;

           if(-1<n && n<=target.getDuration())target.stop(n);
         }

         function onMouseMove(evt){

           evt.preventDefault();

           evt = (evt.originalEvent.touches && evt.originalEvent.touches[0]) || evt;

           if(isMousePress===true){

             speed = (((evt.clientX - centerX)/speedWidth)*power*interval)|0;

           }
         }

         

      });
      //Edge binding end

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

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