/***********************
* 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) {
         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");
         sym.$("solutionBtn").hide();
         function alertMessage(){
         				 alertify.alert("เกิดข้อผิดพลาด","ยังทำแบบฝึกหัดไม่ครบทุกข้อเลย").setting({transition:'fade'}).show(); 
         			}
         
         				var choiceArr = {choice1:"",choice2:"",choice3:"",choice4:""}
         				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"];
         				var s1 = 0;
         				var s2 = 0;
         				var s3 = 0;
         				var s4 = 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 < 5){
                  		choiceArr.choice1 = "done";
                  			switch (intRes){
                  			case 1:
                  			s1 = 1; 
                  			testBox.getSymbol(menuArray[0]).stop("inac");testBox.getSymbol(menuArray[1]).stop("normal");
                  			testBox.getSymbol(menuArray[2]).stop("normal");testBox.getSymbol(menuArray[3]).stop("normal");
                  			break;
                  			case 2:
                  			s1 = 0; 
                  			testBox.getSymbol(menuArray[1]).stop("inac");testBox.getSymbol(menuArray[0]).stop("normal");
                  			testBox.getSymbol(menuArray[2]).stop("normal");testBox.getSymbol(menuArray[3]).stop("normal");
                  			break;
                  			case 3:
                  			s1 = 0; 
                  			testBox.getSymbol(menuArray[2]).stop("inac");testBox.getSymbol(menuArray[1]).stop("normal");
                  			testBox.getSymbol(menuArray[0]).stop("normal");testBox.getSymbol(menuArray[3]).stop("normal");
                  			break;
                  			case 4:
                  			s1 = 0; 
                  			testBox.getSymbol(menuArray[3]).stop("inac");testBox.getSymbol(menuArray[1]).stop("normal");
                  			testBox.getSymbol(menuArray[2]).stop("normal");testBox.getSymbol(menuArray[0]).stop("normal");
                  			break;
                  			}
                  		}else if(intRes>4 && intRes<=7){
                  		choiceArr.choice2 = "done";
                  			switch (intRes){
                  			case 5:
                  			s2 = 0; 
                  			testBox.getSymbol(menuArray[4]).stop("inac");testBox.getSymbol(menuArray[5]).stop("normal");
                  			testBox.getSymbol(menuArray[6]).stop("normal");
                  			break;
                  			case 6:
                  			s2 = 0; 
                  			testBox.getSymbol(menuArray[5]).stop("inac");testBox.getSymbol(menuArray[4]).stop("normal");
                  			testBox.getSymbol(menuArray[6]).stop("normal");
                  			break;
                  			case 7:
                  			s2 = 2; 
                  			testBox.getSymbol(menuArray[6]).stop("inac");testBox.getSymbol(menuArray[5]).stop("normal");
                  			testBox.getSymbol(menuArray[4]).stop("normal");
                  			break;
                  			}
                  		}else if(intRes>7 && intRes<=11){
         
                  			switch (intRes){
                  			case 8:choiceArr.choice3 = "done";
                  			s3 = 0; 
                  			testBox.getSymbol(menuArray[7]).stop("inac");testBox.getSymbol(menuArray[8]).stop("normal");
         
                  			break;
                  			case 9:choiceArr.choice3 = "done";
                  			s3 = 1; 
                  			testBox.getSymbol(menuArray[8]).stop("inac");testBox.getSymbol(menuArray[7]).stop("normal");
         
                  			break;
         
                  			break;
                  			case 10:
                  			choiceArr.choice4 = "done";
                  			s4 = 0; 
                  			testBox.getSymbol(menuArray[9]).stop("inac");testBox.getSymbol(menuArray[10]).stop("normal");
         
                  			break;
         
                  			break;
                  			case 11:choiceArr.choice4 = "done";
                  			s4 = 1; 
                  			testBox.getSymbol(menuArray[10]).stop("inac");testBox.getSymbol(menuArray[9]).stop("normal");
         
                  			break;
                  			}
                  		}
         						if(choiceArr.choice1 != "" && choiceArr.choice2 != "" && choiceArr.choice3 != "" && choiceArr.choice4 != ""){
         								testDone = true;
         								score  = s1+s2+s3+s4;
         
         								console.log("test is done");
         						}
         
                  	}
         
         
         
         				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"];
         		if(testDone == true){
         			sym.getSymbol("mascotMove").play("answer");
         			sym.$("solutionBtn").fadeIn();
         						sym.$("solutionBtn").bind("click",function(){
         								var config = {
         									 width: 637,
         									 height: 480,
         									 type: "animate",
         									 source: "solution_lesson3_7.html"
         								};		
         								EC.Spotlight.open(config);
         						});
         
         			updateScore(score);
         			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: 'ic_no_1'
   (function(symbolName) {   
   
   })("ic_no_1");
   //Edge symbol end:'ic_no_1'

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

   //=========================================================
   
   //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'

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