/***********************
* Adobe Edge Animate 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 Animate
*
***********************/
(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 ship = sym.$("ship");
         var detail = "";
         var boolf = false;
         var tempFlag="";
         var tempNumFlag;
         
         function alertMessage(){
         				 alertify.alert("เกิดข้อผิดพลาด","ยังทำแบบฝึกหัดไม่ครบทุกข้อเลย").setting({transition:'fade'}).show(); 
         			}
         sym.$("solutionBtn").hide();
         for(var i=1;i<=9;i++){
         
         		sym.$("btn_"+i).bind("click",function(){
         			 var posX = sym.$(this).position().left;
         			 var posY = sym.$(this).position().top;
         			 var res = this.id.substring(10);
         			 moveShip(posX,posY,this.id);
         		});
         
         }
         
         function widthWindow(){
         	nowWidth = $(document).width();
         	return nowWidth;
         }  
         
         function moveShip(getX,getY,getI){
         
         		var widthWin = widthWindow();
         
         		if(widthWin <=1024){
         			TweenMax.to(ship,1.2,{css:{x:getX-40,y:getY+65},ease:Quad.easeOut});
         		}else{
         			TweenMax.to(ship,1.2,{css:{x:getX-50,y:getY+55},ease:Quad.easeOut});
         		}
         
         		var res = getI.substring(10)
         		var numFlag = parseInt(res);
               var flag = sym.$("c_"+numFlag);
               var nameFlag = "c_"+numFlag;
         		console.log(numFlag);
         		sym.$("btn_"+numFlag).hide();
         		sym.$("btn_"+tempNumFlag).show();
         
         			if(tempFlag!=flag){
         					TweenMax.to(flag,.8,{css:{scaleX:"1%",scaleY:"1%"},ease:Back.easeOut});
         					TweenMax.to(tempFlag,1,{css:{scaleX:"0%",scaleY:"0%"},ease:Quad.easeOut});
         					tempFlag = flag;
         			}		
         
         			tempNumFlag = numFlag;
         
         		flag.bind("click",function(){
         		var widthFull =789;
         		var heightFull;
         
         		if(numFlag ==3 ||numFlag ==7 ||numFlag ==5 ||numFlag ==6){
         			heightFull = 489;
         		}
         		if(numFlag ==1){
         			heightFull = 511;
         		}
         		if(numFlag ==2){
         			heightFull = 582;
         		}
         		if(numFlag ==4){
         			heightFull = 522;
         		}
         		if(numFlag ==8){
         			heightFull = 542;
         		}
         		if(numFlag ==9){
         			heightFull = 488;
         		}
         			var config = {
         				 width: widthFull,
         				 height: heightFull,
         				 type: "image",
         				 source: "images/air/lesson3_2/fullgraph/"+nameFlag+".png"
         			};		
         
         			EC.Spotlight.open(config);
         		});
         }
         sym.$("btn_next").bind("click",function(){
         	   sym.play("s2");
         });
         
         sym.$("back").bind("click",function(){
         	   sym.play(0);
         });
         
         
         var menuArray = ["ch_1","ch_2","ch_3","ch_4","ch_5","ch_6","ch_7","ch_8","ch_9","ch_10","ch_11","ch_12"];
         				var test1Done = false;
         				var test2Done = false;
         
         				function chooseProgress(getID){
                  		var res = getID.substring(9);
                  		var resName =getID.substring(6);
                  		var intRes = parseInt(res);
                  		var indexArr= intRes-1;
         					console.log(res);
                  		if(intRes < 7){
                  			test1Done =true;
                  			switch (intRes){
                  			case 1: 
                  			sym.getSymbol(menuArray[0]).stop("inac");sym.getSymbol(menuArray[1]).stop("normal");
                  			sym.getSymbol(menuArray[2]).stop("normal");sym.getSymbol(menuArray[3]).stop("normal");
                  			sym.getSymbol(menuArray[4]).stop("normal");sym.getSymbol(menuArray[5]).stop("normal");
                  			break;
                  			case 2:
                  			sym.getSymbol(menuArray[1]).stop("inac");sym.getSymbol(menuArray[0]).stop("normal");
                  			sym.getSymbol(menuArray[2]).stop("normal");sym.getSymbol(menuArray[3]).stop("normal");
                  			sym.getSymbol(menuArray[4]).stop("normal");sym.getSymbol(menuArray[5]).stop("normal");
                  			break;
                  			case 3:
                  			sym.getSymbol(menuArray[2]).stop("inac");sym.getSymbol(menuArray[1]).stop("normal");
                  			sym.getSymbol(menuArray[0]).stop("normal");sym.getSymbol(menuArray[3]).stop("normal");
                  			sym.getSymbol(menuArray[4]).stop("normal");sym.getSymbol(menuArray[5]).stop("normal");
                  			break;
                  			case 4:
                  			sym.getSymbol(menuArray[3]).stop("inac");sym.getSymbol(menuArray[1]).stop("normal");
                  			sym.getSymbol(menuArray[2]).stop("normal");sym.getSymbol(menuArray[0]).stop("normal");
                  			sym.getSymbol(menuArray[4]).stop("normal");sym.getSymbol(menuArray[5]).stop("normal");
                  			break;
                  			case 5:
                  			sym.getSymbol(menuArray[4]).stop("inac");sym.getSymbol(menuArray[1]).stop("normal");
                  			sym.getSymbol(menuArray[2]).stop("normal");sym.getSymbol(menuArray[3]).stop("normal");
                  			sym.getSymbol(menuArray[0]).stop("normal");sym.getSymbol(menuArray[5]).stop("normal");
                  			break;
                  			case 6:
                  			sym.getSymbol(menuArray[5]).stop("inac");sym.getSymbol(menuArray[1]).stop("normal");
                  			sym.getSymbol(menuArray[2]).stop("normal");sym.getSymbol(menuArray[3]).stop("normal");
                  			sym.getSymbol(menuArray[4]).stop("normal");sym.getSymbol(menuArray[0]).stop("normal");
                  			break;
                  			}
                  		}else if(intRes > 6){
                  			test2Done =true;
                  			switch (intRes){
                  			case 7:
                  			sym.getSymbol(menuArray[6]).stop("inac");sym.getSymbol(menuArray[7]).stop("normal");
                  			sym.getSymbol(menuArray[8]).stop("normal");sym.getSymbol(menuArray[9]).stop("normal");
                  			sym.getSymbol(menuArray[10]).stop("normal");sym.getSymbol(menuArray[11]).stop("normal");
                  			break;
                  			case 8:
                  			sym.getSymbol(menuArray[7]).stop("inac");sym.getSymbol(menuArray[6]).stop("normal");
                  			sym.getSymbol(menuArray[8]).stop("normal");sym.getSymbol(menuArray[9]).stop("normal");
                  			sym.getSymbol(menuArray[10]).stop("normal");sym.getSymbol(menuArray[11]).stop("normal");
                  			break;
                  			case 9:
                  			sym.getSymbol(menuArray[8]).stop("inac");sym.getSymbol(menuArray[7]).stop("normal");
                  			sym.getSymbol(menuArray[6]).stop("normal");sym.getSymbol(menuArray[9]).stop("normal");
                  			sym.getSymbol(menuArray[10]).stop("normal");sym.getSymbol(menuArray[11]).stop("normal");
                  			break;
                  			case 10:
                  			sym.getSymbol(menuArray[9]).stop("inac");sym.getSymbol(menuArray[7]).stop("normal");
                  			sym.getSymbol(menuArray[8]).stop("normal");sym.getSymbol(menuArray[6]).stop("normal");
                  			sym.getSymbol(menuArray[10]).stop("normal");sym.getSymbol(menuArray[11]).stop("normal");
                  			break;
                  			case 11:
                  			sym.getSymbol(menuArray[10]).stop("inac");sym.getSymbol(menuArray[7]).stop("normal");
                  			sym.getSymbol(menuArray[8]).stop("normal");sym.getSymbol(menuArray[9]).stop("normal");
                  			sym.getSymbol(menuArray[6]).stop("normal");sym.getSymbol(menuArray[11]).stop("normal");
                  			break;
                  			case 12:
                  			sym.getSymbol(menuArray[11]).stop("inac");sym.getSymbol(menuArray[7]).stop("normal");
                  			sym.getSymbol(menuArray[8]).stop("normal");sym.getSymbol(menuArray[9]).stop("normal");
                  			sym.getSymbol(menuArray[10]).stop("normal");sym.getSymbol(menuArray[6]).stop("normal");
                  			break;
                  			}
                  		}
                  	}
         
         
         
         				for(var i = 0; i<menuArray.length; i++){
                  		sym.$(menuArray[i]).bind("click",function(){
                  				chooseProgress(this.id);
                  		});
         
                  	}
         
         
         sym.$('btnCheck').bind("click",function(){
         	var menuArray = ["ch_1","ch_2","ch_3","ch_4","ch_5","ch_6","ch_7","ch_8","ch_9","ch_10","ch_11","ch_12"];
         		if(test1Done == true && test2Done == true){
         			sym.getSymbol("mascotMove").play("answer");
         			sym.$("solutionBtn").fadeIn();
         						sym.$("solutionBtn").bind("click",function(){
         								var config = {
         									 width: 800,
         									 height: 282,
         									 type: "animate",
         									 source: "solution_lesson3_2.html"
         								};		
         								EC.Spotlight.open(config);
         						});
         			for(var i = 0; i<menuArray.length; i++){
                  		sym.$(menuArray[i]).unbind("click");
                  	}
         
         		}else{
         			alertMessage();
         		}
         });

      });
      //Edge binding end

      Symbol.bindTriggerAction(compId, symbolName, "Default Timeline", 250, function(sym, e) {
         sym.stop();

      });
      //Edge binding end

      Symbol.bindTriggerAction(compId, symbolName, "Default Timeline", 1500, function(sym, e) {
         sym.stop();
         
         
         				

      });
      //Edge binding end

      Symbol.bindSymbolAction(compId, symbolName, "creationComplete", function(sym, e) {
         yepnope({
             load: [
         		"js/edgedock/js/min/EdgeCommons.js",
         		"js/alertifyjs/alertify.min.js",
         		"js/TweenMax.min.js",
         		"js/energize.js",
         		"js/alertifyjs/css/alertify.min.css",
         		"js/alertifyjs/css/themes/default.min.css",
         		"js/edgedock/css/style.css"
         	],
         	complete: function () {
         
              console.log("allscript complete");
           }
         });
         

      });
      //Edge binding end

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

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

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

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

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

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

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

   //=========================================================
   
   //Edge symbol: 'mascotMove'
   (function(symbolName) {   
   
      Symbol.bindTriggerAction(compId, symbolName, "Default Timeline", 0, function(sym, e) {
         sym.stop();

      });
      //Edge binding end

      Symbol.bindTriggerAction(compId, symbolName, "Default Timeline", 2000, function(sym, e) {
         sym.stop();

      });
      //Edge binding end

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

})(jQuery, AdobeEdge, "EDGE-187333172");