/***********************
* 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();
         sym.getSymbol("sym_test").$("ansg").hide();
         window.alertMessage   = function(){
         		 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"];
         				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 < 3){
                  		choiceArr.choice1 = "done";
                  			switch (intRes){
                  			case 1:
                  			s1 = 0; 
                  			testBox.getSymbol(menuArray[0]).stop("inac");testBox.getSymbol(menuArray[1]).stop("normal");
         
                  			break;
                  			case 2:
                  			s1 = 2; 
                  			testBox.getSymbol(menuArray[1]).stop("inac");testBox.getSymbol(menuArray[0]).stop("normal");
         
                  			break;
                  			}
                  			console.log("s1 :"+s1);
                  		}else if(intRes>2 && intRes<=4){
                  		choiceArr.choice2 = "done";
                  			switch (intRes){
                  			case 3:
                  			s2 = 2; 
                  			testBox.getSymbol(menuArray[2]).stop("inac");testBox.getSymbol(menuArray[3]).stop("normal");
         
                  			break;
                  			case 4:
                  			s2 = 0; 
                  			testBox.getSymbol(menuArray[3]).stop("inac");testBox.getSymbol(menuArray[2]).stop("normal");
         
                  			break;
         
                  			}
                  			console.log("s2 :"+s2);
                  		}else if(intRes>4 && intRes<=6){
         
                  			switch (intRes){
                  			case 5:choiceArr.choice3 = "done";
                  			s3 = 2; 
                  			testBox.getSymbol(menuArray[4]).stop("inac");testBox.getSymbol(menuArray[5]).stop("normal");
         
                  			break;
                  			case 6:choiceArr.choice3 = "done";
                  			s3 = 0; 
                  			testBox.getSymbol(menuArray[5]).stop("inac");testBox.getSymbol(menuArray[4]).stop("normal");
         
                  			break;
         
         
                  			}
                  			console.log("s3 :"+s3);
                  		}else if(intRes>6 && intRes<=8){
         
                  			switch (intRes){
                  			case 7:choiceArr.choice4 = "done";
                  			s4 = 0; 
                  			testBox.getSymbol(menuArray[6]).stop("inac");testBox.getSymbol(menuArray[7]).stop("normal");
         
                  			break;
                  			case 8:choiceArr.choice4 = "done";
                  			s4 = 2; 
                  			testBox.getSymbol(menuArray[7]).stop("inac");testBox.getSymbol(menuArray[6]).stop("normal");
         
                  			break;
         
         
                  			}
                  			console.log("s4 :"+s4);
                  		}
         						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"];
         		if(testDone == true){
         			sym.getSymbol("mascotMove").play("answer");
         			sym.getSymbol("mascotin").play("animate");
         			sym.getSymbol("mascotin").getSymbol("balloonText").stop("a1");
         			sym.$("solutionBtn").fadeIn();
         			sym.getSymbol("sym_test").$("ansg").fadeIn(2000);
         						sym.$("solutionBtn").bind("click",function(){
         								var config = {
         									 width: 724,
         									 height: 222,
         									 type: "animate",
         									 source: "solution_lesson4_12.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");
           }
         });

      });
      //Edge binding end

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

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

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

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

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

      });
      //Edge binding end

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

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

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