/***********************
* 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) {
         // insert code to be run when the composition is fully loaded here
         //check Choice
         var tempBtn = "test";
         var boolf = false;
         var chooseCh =0; 
         var activeChoice =0;
         window.alertMessage   = function(){
         		 alertify.alert("เกิดข้อผิดพลาด","ยังทำแบบฝึกหัดไม่ครบทุกข้อเลย").setting({transition:'fade'}).show(); 
         	}
         function enable(btncurr){
         	sym.getSymbol(btncurr).stop("out");
         
         	sym.$(btncurr).bind("click", function(){
         			disable(btncurr,this.id);
         	});
         
         	//console.log("btncurr = "+btncurr);
         }
         
         function disable(btnch,getID) {   
         					sym.getSymbol(btnch).stop("over");
                   		sym.$(btnch).unbind("click");
         					var res = getID.substring(13);
         					console.log(res);
         					chooseCh = res;
         					if(boolf){
         							if(tempBtn!=btnch){
         									//console.log("true");
         									enable(tempBtn);
         							}else{
         									//console.log("false");
         
         							}
         					}else{
         					   boolf = true;
         
         					}
         
                   		tempBtn = btnch;
                   		//console.log("tempBtn = " + tempBtn);
               }
         
         for(var s=1;s<=7;s++){
         		sym.$("btn_q1_"+s).bind("click",function(){
         			console.log("clicked");
         			disable(this,this.id);
         		});
         }
         
         function checkAns1(){
         	if( !boolf){
         		return false;
         	}else{
         		return true
         	}
         }
         
         
         sym.$('checkAns').bind("click",function(){
         	var ifdone = checkAns1();
         	if(ifdone){
         		if(chooseCh==1){
         			sym.getSymbol('mascotMove').play("move");
         			sym.getSymbol('mascotMove').getSymbol("balloonText").play("text1");
         		}else{
         			sym.getSymbol('mascotMove').play("move");
         			sym.getSymbol('mascotMove').getSymbol("balloonText").play("text2");
         		}
         	}else{
         		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: 'btn_q1_1'
   (function(symbolName) {   
   
   })("btn_q1_1");
   //Edge symbol end:'btn_q1_1'

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

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

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

      });
      //Edge binding end

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

      });
      //Edge binding end

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

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

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