/***********************
* 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.bindTriggerAction(compId, symbolName, "Default Timeline", 0, function(sym, e) {
         sym.$('sym_test').css("overflow-x","hidden");
         sym.$('sym_test').css("overflow-y","scroll");
         
         sym.$('sym_test').css("-webkit-overflow-scrolling","touch");
         sym.$('sym_test').css("-ms-overflow-scrolling","touch");
         sym.$('sym_test').css("-moz-overflow-scrolling","touch");

      });
      //Edge binding end

      Symbol.bindElementAction(compId, symbolName, "document", "compositionReady", function(sym, e) {
         function alertMessage(){
         				 alertify.alert("เกิดข้อผิดพลาด","ยังทำแบบฝึกหัดไม่ครบทุกข้อเลย").setting({transition:'fade'}).show(); 
         			}
         sym.$("solutionBtn").hide();
         				var choiceArr = {choice1:"",choice2:"",choice3:"",choice4:"",choice5:"",choice6:""}
         				var testBox = sym.getSymbol("sym_test");
         				var menuArray = ["choice_1","choice_2","choice_3","choice_4","choice_5","choice_6","choice_7","choice_8","choice_9","choice_10","choice_11","choice_12"];
         				var s1 = 0;
         				var s2 = 0;
         				var s3 = 0;
         				var s4 = 0;
         				var s5 = 0;
         				var s6 = 0;
         				var testDone = false;
         				var score =0;
         
         
         				function updateScore(getScore){
                  			var text = getScore +" คะแนน";
                  			sym.getSymbol("mascotMove").getSymbol("balloonScore").$("scoreText").html(text);
                  	}
         
         				function chooseProgress(getID){
         
                  		var res = getID.substring(22);
                  		var resName =getID.substring(15);
                  		var intRes = parseInt(res);
                  		var indexArr= intRes-1;
         					console.log(res);
                  		if(intRes < 3){
                  			switch (intRes){
                  			case 1: choiceArr.choice1 = "yep";
                  			s1 = 0; 
                  			testBox.getSymbol(menuArray[0]).stop("inac");testBox.getSymbol(menuArray[1]).stop("normal");
                  			break;
                  			case 2: choiceArr.choice1 = "non";
                  			s1 = 1;
                  			testBox.getSymbol(menuArray[0]).stop("normal");testBox.getSymbol(menuArray[1]).stop("inac");
                  			break;
                  			}
                  		}else if(intRes>2 && intRes<=4){
                  			switch (intRes){
                  			case 3:choiceArr.choice2 = "yep";
                  			s2 = 0;
                  			testBox.getSymbol(menuArray[2]).stop("inac");testBox.getSymbol(menuArray[3]).stop("normal");
                  			break;
                  			case 4:choiceArr.choice2 = "non";
                  			s2 = 1;
                  			testBox.getSymbol(menuArray[2]).stop("normal");testBox.getSymbol(menuArray[3]).stop("inac");
                  			break;
                  			}
                  		}else if(intRes>4 && intRes<=6){
                  			switch (intRes){
                  			case 5:choiceArr.choice3 = "yep";
                  			s3 = 1;
                  			testBox.getSymbol(menuArray[4]).stop("inac");testBox.getSymbol(menuArray[5]).stop("normal");
                  			break;
                  			case 6:choiceArr.choice3 = "non";
                  			s3 = 0;
                  			testBox.getSymbol(menuArray[4]).stop("normal");testBox.getSymbol(menuArray[5]).stop("inac");
                  			break;
                  			}
                  		}else if(intRes>6 && intRes<=8){
                  			switch (intRes){
                  			case 7:choiceArr.choice4 = "non";
                  			s4 = 0;
                  			testBox.getSymbol(menuArray[6]).stop("inac");testBox.getSymbol(menuArray[7]).stop("normal");
                  			break;
                  			case 8:choiceArr.choice4 = "yep";
                  			s4 = 1;
                  			testBox.getSymbol(menuArray[6]).stop("normal");testBox.getSymbol(menuArray[7]).stop("inac");
                  			break;
                  			}
                  		}else if(intRes>8 && intRes<=10){
                  			switch (intRes){
                  			case 9:choiceArr.choice5 = "non";
                  			s5 = 0;
                  			testBox.getSymbol(menuArray[8]).stop("inac");testBox.getSymbol(menuArray[9]).stop("normal");
                  			break;
                  			case 10:choiceArr.choice5 = "yep";
                  			s5 = 1;
                  			testBox.getSymbol(menuArray[8]).stop("normal");testBox.getSymbol(menuArray[9]).stop("inac");
                  			break;
                  			}
                  		}else if(intRes>10 && intRes<=12){
                  			switch (intRes){
                  			case 11:choiceArr.choice6 = "yep";
                  			s6 = 1;
                  			testBox.getSymbol(menuArray[10]).stop("inac");testBox.getSymbol(menuArray[11]).stop("normal");
                  			break;
                  			case 12:choiceArr.choice6 = "non";
                  			s6 = 0;
                  			testBox.getSymbol(menuArray[10]).stop("normal");testBox.getSymbol(menuArray[11]).stop("inac");
                  			break;
                  			}
                  		}
         						if(choiceArr.choice1 != "" && choiceArr.choice2 != "" && choiceArr.choice3 != "" && choiceArr.choice4 != ""&& choiceArr.choice5 != ""&& choiceArr.choice6 != ""){
         								testDone = true;
         								score  = s1+s2+s3+s4+s5+s6;
         								updateScore(score);
         								console.log("test is done");
         						}
                  		console.log(choiceArr.choice1+"\n"+choiceArr.choice2+"\n"+choiceArr.choice3+"\n"+choiceArr.choice4+"\n"+choiceArr.choice5+"\n"+choiceArr.choice6);
                  	}
         
         
         
         				for(var i = 0; i<menuArray.length; i++){
                  		testBox.$(menuArray[i]).bind("click",function(){
                  				chooseProgress(this.id);
                  		});
         
                  	}
         
         
         sym.$('btnCheck').bind("click",function(){
         	var menuArray = ["choice_1","choice_2","choice_3","choice_4","choice_5","choice_6","choice_7","choice_8","choice_9","choice_10","choice_11","choice_12"];
         		if(testDone == true){
         			sym.getSymbol("mascotMove").play("answer");
         			sym.$("solutionBtn").fadeIn();
         						sym.$("solutionBtn").bind("click",function(){
         								var config = {
         									 width: 744,
         									 height: 480,
         									 type: "animate",
         									 source: "solution_lesson2_9.html"
         								};		
         								EC.Spotlight.open(config);
         						});
         			for(var i = 0; i<menuArray.length; i++){
                  		testBox.$(menuArray[i]).unbind("click");
                  	}
         
         		}else{
         			console.log("can't check");
         			alertMessage();
         		}
         });

      });
      //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");
              sym.play();
           }
         });

      });
      //Edge binding end

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

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

      });
      //Edge binding end

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      });
      //Edge binding end

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

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

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

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

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