/* -----------------------------------------------------------------------------

ListeningSlideController

----------------------------------------------------------------------------- */
ListeningSlideController = Class.extend(
  SlideController,
  {

    //プロパティ----------------------------------------------------------------
    context     : {},			//initialize時必須
    type        : "",			//initialize時必須
    slidenumber : "",			//initialize時必須
    slideid     : "",			//initialize時必須
    template    : "",			//initialize時必須

    mode        : "challenge",  //challenge|review
    nextflash : "",

    examNo      : 0,
    part        : 0,
    major       : 0,

    //※以下はタイプがquestion以外のSlideでは無効なプロパティ
    q_no        : "",         //initialize時必須
    partQuestionCount: 0, //同一パート内での出題番号
    //question_id : "",     //question_id
    answer      : "",
    useranswer  : "",
    data        : {},
    solution    : false,

    //メソッド------------------------------------------------------------------
    initialize: function(slideId,param) {
      this.parent( slideId );
      this.slideContent = $("div", $("#" + slideId));
    },

    //全スライド共通初期化処理
    commonInitialize: function(slideId,param) {
      this.parent( slideId );
      this.slideContent = $("div", $("#" + slideId));

      if( param.type != "" ){
        this.type     = param.type;
      }

      this.slidenumber= param.slide_number;
      this.slideid    = slideId;
      this.data       = param.data;

      if( this.type == "question" ){
        this.examNo   = param.data.num;
        this.part     = param.data.part;
      }

    },

    setContext: function( context ){
      //Slideを統べる親クラス（Context）をセット
      //※SlideからContextにはcontext.notifyメソッド経由で通知すること

      this.context = context;

    },

    play: function(){
      //外部からSlide(Question)を開始するメソッドです

      alert("この機能は未実装です：play");

    },

    stop: function(){
      //外部からSlide(Question)を終了するメソッドです

      alert("この機能は未実装です：stop");

    },

    toggleGuess: function(){

      alert("この機能は未実装です：toggleGuess");

    },

    commit: function(){

      alert("この機能は未実装です：commit");

    },

    dispQuestion: function(){

      alert("この機能は未実装です：dispQuestion");

      this.context.notify('thinking');

    },

    //FlashProxyから再生終了通知を受け取るメソッド-----------------------------
    //  ※現在再生中のSWF・MP3が終了したときに呼ばれるメソッドです
    flashComplete: function(){

      switch( this.nextflash ){

        case "loopsound":
          //ループ音声を再生 ※VolumeCheckのみ
          this.stopFlashMovie();
          this.playLoopSound();
          break;

        case "q_sound":
          //Flv終了後、問題音声を再生
          this.stopFlashMovie();
          this.playQuestionSound();
          break;

        case "question":
          //音声終了後問題を表示　※questionのみ
          this.stopQuestionSound();
          this.dispQuestion();
          break;

        case "nextslide":
          //音声終了後自動で次のスライドへ
          this.stopFlashMovie();
          this.stopQuestionSound();
          this.context.notify('next');
          break;

        default:
          //なにもしない
          break;

      }

    },

    //Timerの操作-----------------------------------------------------------
    showTimer: function(){
      //Timerそのもののshow
      this.context.components["timer"].show();
    },
    hideTimer: function(){
      //Timerそのもののhide
      this.context.components["timer"].hide();
    },
    showTimerCounter: function(){
      //TimerCounterのshow
      $("#timer_diplay").show();
    },
    hideTimerCounter: function(){
      //TimerCounterのhide
      $("#timer_diplay").hide();
    },

    //Questionの操作-----------------------------------------------------------
    setTrueAnswer: function(){
      //各typeのクラスメソッドを参照してください

      alert("この機能は未実装です：setTrueAnswer");

    },

    setUserAnswer: function(){
      //各typeのクラスメソッドを参照してください

      alert("この機能は未実装です：setUserAnswer");

    },

    updateUserAnswewr: function(){
      //各typeのクラスメソッドを参照してください

      alert("この機能は未実装です：updateUserAnswewr");

    },

    toggleSolution: function(){
      //各typeのクラスメソッドを参照してください
      alert("この機能は未実装です：toggleSolution");
    },

    setResult: function(){
      //同期通信でカレントスライドの成績・進捗を更新する。PAUSE、FINISHなど確実にResultをpushしたいときはこっち
      if( this.solution == 1 ){
        r.show_solution(1);
      }
      if( this.useranswer != "" && this.useranswer != undefined ){
        var temp = String(this.useranswer);
        r.user_answer(temp);
      }
      return r.push();
    },

    setCurrentResult: function(){
      //非同期通信でカレントスライドの成績・進捗を更新する。スライドのstopなど、ページ遷移を伴わない場合のみ使用可能
      if( this.solution == 1 ){
        r.show_solution(1);
      }
      if( this.useranswer != "" ){
        var temp = String(this.useranswer);
        r.user_answer(temp);
      }
      r.push_current();
    },

    setPartDone: function(){
      //r.push();
    },

    setFinish: function(){
      r.done();
    },

    playFlashMovie: function(){
      //該当typeのクラスメソッドを参照してください
      alert("この機能は未実装です：playFlashMovie");
    },

    stopFlashMovie: function(){
      var player_area_id = this.slideid+"_FlvPlayer";
      $("#"+player_area_id).html("");
    },

    playSound: function(){
      //該当typeのクラスメソッドを参照してください
      alert("この機能は未実装です：playSound");
    },

    playQuestionSound: function(){

      //出題テキストを表示
      $("#"+this.slideid+" .question").show();

      this.nextflash = "question";

      var tempExamNo = String("0"+this.examNo).slice(-2);
      var tempPart   = String("0"+this.part).slice(-2);
      var tempMajor  = String("0"+this.major).slice(-2);
      var tempMinor  = String("00"+this.q_no).slice(-3);

      var filename = tempExamNo + '-L-' + tempPart + '-' + tempMajor + '-' + tempMinor + '.mp3';

      var playlist = [
        {
          "name" : "list",
          "value": [
            {
               path:root+"static/mp3/exam/"+filename
            }
          ]
        },
        {
            "name" : "autoplay",
            "value": true
        }
      ]

      createMP3Player( this, playlist );
    },

    stopQuestionSound: function(){
      $("#MP3PlayerArea").html("");
    }
    
  }
);


/* -----------------------------------------------------------------------------

ListeningSlideController_Intro

----------------------------------------------------------------------------- */
ListeningSlideController_Intro = Class.extend(
  ListeningSlideController,
  {
    //プロパティ----------------------------------------------------------------
    //メソッド------------------------------------------------------------------
    initialize: function(slideId,param) {

      //全スライド共通初期化処理
      this.commonInitialize(slideId,param);
      
    },

    play: function(){
      //外部からSlide(Question)を開始するメソッドです

      //タイマー停止
      this.context.components["timer"].pauseTimer();

      //Timerエリアの非表示
      this.hideTimer();

    },

    stop: function(){
      //外部からSlide(Question)を終了するメソッドです
    }
  }
);

/* -----------------------------------------------------------------------------

ListeningSlideController_VolumeCheck

----------------------------------------------------------------------------- */
ListeningSlideController_VolumeCheck = Class.extend(
  ListeningSlideController,
  {
    //プロパティ----------------------------------------------------------------
    //メソッド------------------------------------------------------------------
    initialize: function(slideId,param) {

      //全スライド共通初期化処理
      this.commonInitialize(slideId,param);

    },

    play: function(){
      //外部からSlide(Question)を開始するメソッドです
      this.playSound();

      //タイマー停止
      this.context.components["timer"].pauseTimer();

      //Timerエリアの非表示
      this.hideTimer();

    },

    stop: function(){
      //外部からSlide(Question)を終了するメソッドです
      this.stopQuestionSound();
    },

    playSound: function(){
      this.nextflash = "loopsound";
      
      var playlist = [
        {
          "name" : "list",
          "value": [
            {
               path:root+"static/mp3/exam/Dir2-2.mp3"
            }
          ]
        },
        {
            "name" : "autoplay",
            "value": true
        },
        {
            "name" : "loop",
            "value": ""       // "" or "one" or "all"
        }
      ]

      createMP3Player( this, playlist );
    },

    playLoopSound: function(){
      this.nextflash = "stay";
      
      var playlist = [
        {
          "name" : "list",
          "value": [
            {
               path:root+"static/mp3/exam/volumecheck01.mp3"
            }
          ]
        },
        {
            "name" : "autoplay",
            "value": true
        },
        {
            "name" : "loop",
            "value": "all" // "" or "one" or "all"
        }
      ]

      createMP3Player( this, playlist );
    }
    
  }
);


/* -----------------------------------------------------------------------------

ListeningSlideController_Direction

----------------------------------------------------------------------------- */
ListeningSlideController_Direction = Class.extend(
  ListeningSlideController,
  {
    //プロパティ----------------------------------------------------------------
    //メソッド------------------------------------------------------------------
    initialize: function(slideId,param) {

      //全スライド共通初期化処理
      this.commonInitialize(slideId,param);

      var tempSlideController = this;
      $("#"+this.slideid+" .skipIntro").ready(
        function(e){
          $("#"+tempSlideController.slideid+" .skipIntro span").bind(
            "click",
            tempSlideController,
            function(e) {
              tempSlideController.skipIntro();
            }
          );
        }
      );

    },

    play: function(){
      //外部からSlide(Question)を開始するメソッドです
      this.playSound();

      //タイマー停止
      this.context.components["timer"].pauseTimer();

      //Timerエリアの非表示
      this.hideTimer();

    },

    stop: function(){
      //外部からSlide(Question)を終了するメソッドです
      this.stopQuestionSound();
    },

    playSound: function(){
      this.nextflash = "nextslide";

      var playlist = [
        {
          "name" : "list",
          "value": [
            {
               path:root+"static/mp3/exam/Dir2-3.mp3"
            }
          ]
        },
        {
            "name" : "autoplay",
            "value": true
        }
      ]

      createMP3Player( this, playlist );
    },
    
    skipIntro: function(){
      c.notify('next');
    }
    

  }
);


/* -----------------------------------------------------------------------------

ListeningSlideController_Passage

----------------------------------------------------------------------------- */
ListeningSlideController_Passage = Class.extend(
  ListeningSlideController,
  {
    //プロパティ----------------------------------------------------------------
    //メソッド------------------------------------------------------------------
    initialize: function(slideId,param) {

      //全スライド共通初期化処理
      this.commonInitialize(slideId,param);

      //※下の値はlistening_rootでセットしています
      this.examNo = param.exam;
      this.part   = param.part;
      this.major  = param.major;
    },

    play: function(){
      //外部からSlide(Question)を開始するメソッドです
      this.playFlashMovie();

      //タイマー停止
      this.context.components["timer"].pauseTimer();

      //Timerエリアの非表示
      this.hideTimer();

    },

    stop: function(){
      //外部からSlide(Question)を終了するメソッドです
      this.stopQuestionSound();
      this.stopFlashMovie();
    },

    playFlashMovie: function(){
      this.nextflash = "nextslide";
      var player_area_id = this.slideid+"_FlvPlayer";
      //createFlvPlayer(this,player_area_id);

      var tempExamNo = String("0"+this.examNo).slice(-2);
      var tempPart   = String("0"+this.part).slice(-2);
      var tempMajor  = String("0"+this.major).slice(-2);

      var filename = tempExamNo + '-L-' + tempPart + '-' + tempMajor + '-000.swf';
      createFlvPlayer(this,player_area_id,filename);
    }
    
  }
);



/* -----------------------------------------------------------------------------

ListeningSlideController_Instruction

----------------------------------------------------------------------------- */
ListeningSlideController_Instruction = Class.extend(
  ListeningSlideController,
  {
    //プロパティ----------------------------------------------------------------
    //メソッド------------------------------------------------------------------
    initialize: function(slideId,param) {

      //全スライド共通初期化処理
      this.commonInitialize(slideId,param);
      this.timerId;
    },

    slideTimeout: function(){
      this.context.notify('next');
    },

    play: function(){
      //外部からSlide(Question)を開始するメソッドです
      var tempController = this;

      //タイマー停止
      this.context.components["timer"].pauseTimer();

      //Timerエリアの非表示
      this.hideTimer();

      //3秒後にnext
      this.timerId = setTimeout(
        function(){ tempController.slideTimeout(tempController) },
        3000
      );
    },

    stop: function(){
      //外部からSlide(Question)を終了するメソッドです
      clearTimeout(this.timerId);
    }
    
  }
);



/* -----------------------------------------------------------------------------

ListeningSlideController_Qtype_t

----------------------------------------------------------------------------- */
ListeningSlideController_Qtype_t = Class.extend(
  ListeningSlideController,
  {
    //プロパティ----------------------------------------------------------------
    //メソッド------------------------------------------------------------------
    initialize: function(slideId,param) {

      //全スライド共通初期化処理
      this.commonInitialize(slideId,param);

      this.partQuestionCount = param.partQuestionCount;
      this.major      = this.data.major;
      this.q_no       = this.data.minor;
      //this.question_id= "q_"+this.q_no;
      this.answer     = this.data.correct_answer;

      var tempSlideController = this;
      var tempQuestionName    = "#"+this.slideid+" li#q"+this.major+"_"+this.q_no+"_";

      $("#"+this.slideid).ready(
        function(e){
          for( var i = 1 ; i <= 4 ; i++ ){
            $(tempQuestionName+i).bind(
              "click",
              tempSlideController,
              function(e) {
                tempSlideController.setUserAnswer({
                  "targetElement":jQuery(this),
                  "userAnswer":jQuery(this).attr("id").split('_')[2]
                });
              }
            );
          }

        }
      );
    },

    play: function(){
      //外部からSlide(Question)を開始するメソッドです

      this.hideQuestion();

      //Resultを更新
      r.seek(this.partQuestionCount);

      //既存の成績の書き戻し
      this.useranswer = r.user_answer();
      if( this.useranswer != "" ){
        this.revertUserAnswer();
      }

      //ShowSolutionボタンのONOFF
      this.solution = r.saw_solution();
      if( this.solution ){
        c.notify('sawSolution');
        this.showSolution();
      }

      this.playQuestionSound();

      //Timerエリアの表示
      this.showTimer();

      //タイマー停止
      this.context.components["timer"].pauseTimer();

    },

    stop: function(){
      //外部からSlide(Question)を終了するメソッドです

      //タイマー停止
      this.context.components["timer"].pauseTimer();

      this.stopQuestionSound();

      //成績・進捗を更新
      this.setCurrentResult();
    },

    dispQuestion: function() {

      $("#"+this.slideid+" .user_answer_area").show();

      this.context.notify('thinking');
      //既存の成績の存在をチェック
      if( this.useranswer ){
        this.context.notify('answerd');
      }

      //タイマー起動
      this.context.components["timer"].startTimer();
      this.context.components["timer"].show();

    },

    hideQuestion: function() {

      $("#"+this.slideid+" .user_answer_area").hide();

    },

    toggleSolution: function(){

      this.dispQuestion();

      if( this.solution ){
        this.hideSolution();
      }
      else{
        this.showSolution();
      }

    },

    showSolution: function(){
      var tempQuestionName    = "#"+this.slideid+" li#q"+this.major+"_"+this.q_no+"_"+this.answer;
      $(tempQuestionName).addClass("showSolution");
      this.solution = 1;
      this.context.notify('answerd');
    },

    hideSolution: function(){
      var tempQuestionName    = "#"+this.slideid+" li#q"+this.major+"_"+this.q_no+"_"+this.answer;
      $(tempQuestionName).removeClass("showSolution");
      this.solution = 0;
    },


    setUserAnswer: function(param){
      this.resetUserAnswer();
      param.targetElement.addClass("radio_select");
      this.useranswer = param.userAnswer;
      this.context.notify('answerd');
      //alert( param.userAnswer == "q"+this.q_no+"_"+this.answer ? "正解！": "不正解..." );
    },

    revertUserAnswer: function(param){
      var tempSlideName    = "#slide_"+this.slidenumber;
      var tempQuestionName = "li#q"+this.major+"_"+this.q_no+"_";

      for( var i = 1 ; i <= 4 ; i++ ){
        if( this.useranswer != i ){
          $(tempQuestionName+i).removeClass("radio_select");
        }
        else{
          $(tempQuestionName+i).addClass("radio_select");
        }
      }
    },

    setTrueAnswer: function(){

      var tempSlideName    = "#slide_"+this.slidenumber;
      var tempQuestionName = "li#a"+this.q_no+"_";

      for( var i = 1 ; i <= 4 ; i++ ){
        if( this.answer != i ){
          $(tempQuestionName+i).removeClass("radio_select");
        }
        else{
          $(tempQuestionName+i).addClass("radio_select");
        }
      }

    },

    resetUserAnswer: function(){

      var tempSlideName    = "#"+this.slideid;
      var tempQuestionName = "li#q"+this.major+"_"+this.q_no+"_";
      for( var i = 1 ; i <= 4 ; i++ ){
        $(tempQuestionName+i).removeClass("radio_select");
      }
      this.useranswer = "";

    }

  }
);

/* -----------------------------------------------------------------------------

ListeningSlideController_Qtype_s

----------------------------------------------------------------------------- */
ListeningSlideController_Qtype_s = Class.extend(
  ListeningSlideController,
  {
    //プロパティ----------------------------------------------------------------
    
    //メソッド------------------------------------------------------------------
    initialize: function(slideId,param) {

      //全スライド共通初期化処理
      this.commonInitialize(slideId,param);

      this.partQuestionCount = param.partQuestionCount;
      this.major      = this.data.major;
      this.q_no       = this.data.minor;
      //this.question_id= "q_"+this.q_no;
      this.answer     = this.data.correct_answer;

      var tempSlideController = this;
      var tempQuestionName    = "#"+this.slideid+" li#q"+this.major+"_"+this.q_no+"_";

      $("#"+this.slideid).ready(
        function(e){
          for( var i = 1 ; i <= 4 ; i++ ){
            $(tempQuestionName+i).bind(
              "click",
              tempSlideController,
              function(e) {
                tempSlideController.setUserAnswer({
                  "targetElement":jQuery(this),
                  "userAnswer":jQuery(this).attr("id").split('_')[2]
                });
              }
            );
          }
        }
      );
    },

    play: function(){
      //外部からSlide(Question)を開始するメソッドです

      this.hideQuestion();

      //Resultを更新
      r.seek(this.partQuestionCount);

      //既存の成績の書き戻し
      this.useranswer = r.user_answer();
      if( this.useranswer != "" ){
        this.revertUserAnswer();
      }
      //ShowSolutionボタンのONOFF
      this.solution = r.saw_solution();
      if( this.solution ){
        c.notify('sawSolution');
        this.showSolution();
      }

      this.playFlashMovie();

      //Timerエリアの表示
      this.showTimer();

      //タイマー停止
      this.context.components["timer"].pauseTimer();

    },

    stop: function(){
      //外部からSlide(Question)を終了するメソッドです

      //タイマー停止
      this.context.components["timer"].pauseTimer();

      this.stopQuestionSound();
      this.stopFlashMovie();

      //成績・進捗を更新
      this.setCurrentResult();
    },

    playFlashMovie: function(){
      this.nextflash = "q_sound";
      var player_area_id = this.slideid+"_FlvPlayer";

      var tempExamNo = String("0"+this.examNo).slice(-2);
      var tempPart   = String("0"+this.part).slice(-2);
      var tempMajor  = String("0"+this.major).slice(-2);
      var tempMinor  = String("00"+this.q_no).slice(-3);
      var filename = tempExamNo + '-L-' + tempPart + '-' + tempMajor + '-' + tempMinor + '.swf';

      createFlvPlayer(this,player_area_id,filename);
    },

    showShortPassage: function() {
      $("#"+this.slideid+" .ShortPassageMovie").show();
    },

    hideShortPassage: function() {
      $("#"+this.slideid+" .ShortPassageMovie").hide();
    },
    
    dispQuestion: function() {
      $("#"+this.slideid+" .question").show();
      $("#"+this.slideid+" .user_answer_area").show();

      this.context.notify('thinking');
      //既存の成績の存在をチェック
      if( this.useranswer ){
        this.context.notify('answerd');
      }

      //タイマー起動
      this.context.components["timer"].startTimer();
      this.context.components["timer"].show();

    },

    hideQuestion: function() {
      $("#"+this.slideid+" .question").hide();
      $("#"+this.slideid+" .user_answer_area").hide();
    },

    toggleSolution: function(){

      this.dispQuestion();

      if( this.solution ){
        this.hideSolution();
      }
      else{
        this.showSolution();
      }

    },

    showSolution: function(){
      var tempQuestionName    = "#"+this.slideid+" li#q"+this.major+"_"+this.q_no+"_"+this.answer;
      $(tempQuestionName).addClass("showSolution");
      this.solution = 1;
      this.context.notify('answerd');
    },

    hideSolution: function(){
      var tempQuestionName    = "#"+this.slideid+" li#q"+this.major+"_"+this.q_no+"_"+this.answer;
      $(tempQuestionName).removeClass("showSolution");
      this.solution = 0;
    },

    setUserAnswer: function(param){
      //alert("clicked "+param.userAnswer+" : "+param.targetElement.attr("id")+" : "+param.targetElement.text());

      this.resetUserAnswer();
      param.targetElement.addClass("radio_select");
      this.useranswer = param.userAnswer;
      this.context.notify('answerd');

      //alert( param.userAnswer == "q"+this.q_no+"_"+this.answer ? "正解！": "不正解..." );

    },

    revertUserAnswer: function(param){
      var tempSlideName    = "#slide_"+this.slidenumber;
      var tempQuestionName = "li#q"+this.major+"_"+this.q_no+"_";

      for( var i = 1 ; i <= 4 ; i++ ){
        if( this.useranswer != i ){
          $(tempQuestionName+i).removeClass("radio_select");
        }
        else{
          $(tempQuestionName+i).addClass("radio_select");
        }
      }
    },
    
    setTrueAnswer: function(){

      var tempSlideName    = "#slide_"+this.slidenumber;
      var tempQuestionName = "#"+this.slideid+" li#a"+this.major+"_"+this.q_no+"_";

      for( var i = 1 ; i <= 4 ; i++ ){
        if( this.answer != i ){
          $(tempQuestionName+i).removeClass("radio_select");
        }
        else{
          $(tempQuestionName+i).addClass("radio_select");
        }
      }

    },

    resetUserAnswer: function(){

      var tempSlideName    = "#slide_"+this.slidenumber;
      var tempQuestionName = "#"+this.slideid+" li#q"+this.major+"_"+this.q_no+"_";
      for( var i = 1 ; i <= 4 ; i++ ){
        $(tempQuestionName+i).removeClass("radio_select");
      }

    },

    playQuestionSound: function(){

      //出題テキストを表示
      $("#"+this.slideid+" .question").show();

      this.nextflash = "question";

      var tempExamNo = String("0"+this.examNo).slice(-2);
      var tempPart   = String("0"+this.part).slice(-2);
      var tempMajor  = String("0"+this.major).slice(-2);
      var tempMinor  = String("00"+this.q_no).slice(-3);

      var filename = tempExamNo + '-L-' + tempPart + '-' + tempMajor + '-' + tempMinor + '-02.mp3';

      var playlist = [
        {
          "name" : "list",
          "value": [
            {
               path:root+"static/mp3/exam/"+filename
            }
          ]
        },
        {
            "name" : "autoplay",
            "value": true
        }
      ]

      createMP3Player( this, playlist );
    }

  }
);

/* -----------------------------------------------------------------------------

ListeningSlideController_Qtype_c

----------------------------------------------------------------------------- */
ListeningSlideController_Qtype_c = Class.extend(
  ListeningSlideController,
  {
    initialize: function(slideId, param) {

      //全スライド共通初期化処理
      this.commonInitialize(slideId,param);

      this.partQuestionCount = param.partQuestionCount;
      this.major        = this.data.major;
      this.q_no         = this.data.minor;
      //this.question_id  = "q_"+this.q_no;

      this.answer       = this.data.correct_answer;
      this.useranswer   = "";

      this.rowlength = this.data.row_h_e.length;
      this.collength = this.data.col_h_e.length;

      //チェックされている箇所に1を入れる配列
      this.tempUserAnswer = new Array(this.rowlength);
      for( var i = 0 ; i < this.tempUserAnswer.length ; i++ ){
        this.tempUserAnswer[i] = new Array(this.collength);
      }

      this.checked_num  = 0;
      this.template = param.template;


      var tempSlideController = this;

      $("#"+this.slideid).ready(
        function(e){
          //チェックボックス（問題の列数でループ）
          for( var i = 1 ; i <= tempSlideController.data.row_h_e.length ; i++ ){
            //チェックボックス（問題の行数でループ）
            for( var j = 1 ; j <= tempSlideController.data.col_h_e.length ; j++ ){
              var targetElementId = "#q"+tempSlideController.major+"_"+tempSlideController.q_no+"_"+i+"_"+j;
              $(targetElementId).bind(
                "click",
                tempSlideController,
                function(e) {
                  tempSlideController.setUserAnswer({
                    "targetElement":jQuery(this)
                  });
                }
              );
            }
          }

        }
      );
    },

    play: function(){
      //外部からSlide(Question)を開始するメソッドです
      this.hideQuestion();

      //Resultを更新
      r.seek(this.partQuestionCount);

      //既存の成績の書き戻し
      this.useranswer = r.user_answer();
      if( this.useranswer != "" ){
        //this.useranswer = eval("["+r.user_answer()+"]");
        this.revertUserAnswer();
      }

      //ShowSolutionボタンのONOFF
      this.solution = r.saw_solution();
      if( this.solution ){
        c.notify('sawSolution');
        this.showSolution();
      }

      this.playQuestionSound();

      //Timerエリアの表示
      this.showTimer();

      //タイマー停止
      this.context.components["timer"].pauseTimer();

    },

    stop: function(){
      //外部からSlide(Question)を終了するメソッドです

      //タイマー停止
      this.context.components["timer"].pauseTimer();

      this.stopQuestionSound();

      var temp1;
      var temp2;
      var currentcolcount = 0;
      this.useranswer = "";
      for( var i = 0 ; i < this.collength ; i++ ){
        for( var j = 0 ; j < this.rowlength ; j++ ){
          if( this.tempUserAnswer[j][i] == 1 ){
            if( currentcolcount != i ){
              currentcolcount++;
              //列の切り替わりで|を追加
              this.useranswer += "|";
            }
            else{
              if( this.useranswer != "" ){
                //区切り文字,を追加
                this.useranswer += ",";
              }
            }
            this.useranswer += (j+1);
          }
        }
      }
      //alert("this.useranswer="+this.useranswer);
      //成績・進捗を更新
      this.setCurrentResult();
    },

    dispQuestion: function() {
      $("#"+this.slideid+" .user_answer_area").show();

      this.context.notify('thinking');
      //次に進めるかどうかチェック
      this.checkAnswerNum();

      //タイマー起動
      this.context.components["timer"].startTimer();
      this.context.components["timer"].show();

    },

    hideQuestion: function() {
      $("#"+this.slideid+" .user_answer_area").hide();
    },

    toggleSolution: function(){
      
      if ( $("#"+this.slideid+" .user_answer_area").css("display") != "none" ){
        this.hideQuestion();
        $("#"+this.slideid+" .true_answer_area").show();
      }
      else{
        $("#"+this.slideid+" .true_answer_area").hide();
        this.dispQuestion();
      }
      this.context.notify('answerd');

    },

    setUserAnswer: function(param){
      var targetrowcount = param.targetElement.attr("id").split('_')[2]-1;
      var targetcolcount = param.targetElement.attr("id").split('_')[3]-1;
      
      for( var i = 1 ; i <= this.collength ; i++ ){
        var targetElementId = "#"+param.targetElement.attr("id").substr(0,param.targetElement.attr("id").length-1)+i;
        $(targetElementId).removeClass("select");
        this.tempUserAnswer[targetrowcount][(i-1)]="";
      }
      param.targetElement.addClass("select");
      //alert(param.targetElement.attr("id").split('_')[2]+"_"+param.targetElement.attr("id").split('_')[3]);
      this.tempUserAnswer[targetrowcount][targetcolcount]=1;

      //次に進めるかどうかチェック
      this.checkAnswerNum();
    },

    revertUserAnswer: function(){

      for( var i = 0 ; i < this.data.row_h_e.length ; i++ ){
        for( var j = 0 ; j < this.data.col_h_e.length ; j++ ){
          this.tempUserAnswer[i][j] = 0;
        }
      }
      
      var temp1 = this.useranswer.split("|");
      var temp2;
      for( var i = 0 ; i < temp1.length ; i++ ){
        temp2 = temp1[i].split(",");
        if( temp2 != ""){
          for( var j = 0 ; j < temp2.length ; j++ ){
            this.tempUserAnswer[(temp2[j]-1)][i] = 1;
          }
        }
      }

      var tempSlideName    = "#"+this.slideid;
      var tempQuestionName = "#q"+this.major+"_"+this.q_no+"_";
      for( var i = 0 ; i < this.rowlength ; i++ ){
        for( var j = 0 ; j < this.collength ; j++ ){
          if( this.tempUserAnswer[i][j] == 1 ){
            $(tempSlideName+" "+tempQuestionName+(i+1)+"_"+(j+1)).addClass("select");
          }
          else{
            $(tempSlideName+" "+tempQuestionName+(i+1)+"_"+(j+1)).addClass("unselect");
          }
        }
      }
    },

    checkAnswerNum: function(){

      var checked = 1;

      for( var i = 0 ; i < this.data.row_h_e.length ; i++ ){

        var tempchecked = 0;
        for( var j = 0 ; j < this.data.col_h_e.length ; j++ ){
          if( this.tempUserAnswer[i][j] ){
            //この行にチェックがあればtempcheckedは1
            tempchecked = 1;
          }
        }

        if( !tempchecked ){
          //この行にチェックがなければcheckedは0
          checked = 0;
        }

      }
      
      //すべての行にチェックがあればcheckedは1のまま。チェックの無い行があればcheckedは0
      if(checked){
        this.context.notify('answerd');
      }

    },

    setTrueAnswer: function(){
      alert("setTrueAnswer");
    }

  }
);

/* -----------------------------------------------------------------------------

ListeningSlideController_Qtype_m

----------------------------------------------------------------------------- */
ListeningSlideController_Qtype_m = Class.extend(
  ListeningSlideController,
  {
    initialize: function(slideId, param) {

      //全スライド共通初期化処理
      this.commonInitialize(slideId,param);

      this.partQuestionCount = param.partQuestionCount;
      this.major      = this.data.major;
      this.q_no         = this.data.minor;

      this.answer       = this.data.correct_answer;
      this.useranswer   = new Array();

      this.checked_num  = 0;

      this.template = param.template;


      var tempSlideController = this;
      var tempQuestionName    = "#"+this.slideid+" li#q"+this.major+"_"+this.q_no+"_";

      $("#"+this.slideid).ready(
        function(e){
          for( var i = 1 ; i <= tempSlideController.data.choice_e.length ; i++ ){
            $(tempQuestionName+i).bind(
              "click",
              tempSlideController,
              function(e) {
                tempSlideController.setUserAnswer({
                  "targetElement":jQuery(this)
                });
              }
            );
          }
        }
      );
      
      return this;

    },

    play: function(){
      //外部からSlide(Question)を開始するメソッドです
      this.hideQuestion();

      //Resultを更新
      r.seek(this.partQuestionCount);

      //既存の成績の書き戻し
      this.useranswer = r.user_answer();
      if( this.useranswer != "" ){
        this.useranswer = eval("["+r.user_answer()+"]");
        this.revertUserAnswer();
      }

      //ShowSolutionボタンのONOFF
      this.solution = r.saw_solution();
      if( this.solution ){
        c.notify('sawSolution');
        this.showSolution();
      }

      this.playQuestionSound();

      //Timerエリアの表示
      this.showTimer();

      //タイマー停止
      this.context.components["timer"].pauseTimer();

    },

    stop: function(){
      //外部からSlide(Question)を終了するメソッドです

      //タイマー停止
      this.context.components["timer"].pauseTimer();

      this.stopQuestionSound();
      //成績・進捗を更新
      this.setCurrentResult();
    },

    dispQuestion: function() {
      $("#"+this.slideid+" .user_answer_area").show();

      this.context.notify('thinking');

      //現在の回答数をチェック
      var tempUserAnswer = new Array;
      for( var i = 0 ; i < this.useranswer.length ; i++ ){
        tempUserAnswer[ this.useranswer[i]-1 ] = 1;
      }
      this.checked_num = 0;
      for( var i = 0 ; i < tempUserAnswer.length ; i++ ){
        if( tempUserAnswer[i] == 1 ){
          this.checked_num++;
        }
      }
      if( this.checked_num == 2 ){
        this.context.notify('answerd');
      }

      //タイマー起動
      this.context.components["timer"].startTimer();

    },

    hideQuestion: function() {
      $("#"+this.slideid+" .user_answer_area").hide();
    },

    toggleSolution: function(){

      if( !this.solution ){
        this.showSolution();
      }
      else{
        this.hideSolution();
      }
      
    },

    showSolution: function(param){
      var tempAnswer = String(this.answer).split(",");
      var tempQuestionName    = "#"+this.slideid+" li#q"+this.major+"_"+this.q_no+"_";

      for(var i = 0 ; i < tempAnswer.length ; i++ ){
        $(tempQuestionName+tempAnswer[i]).addClass("showSolution");
      }
      this.solution = 1;
      this.context.notify('answerd');
    },
    
    hideSolution: function(param){
      var tempAnswer = String(this.answer).split(",");
      var tempQuestionName    = "#"+this.slideid+" li#q"+this.major+"_"+this.q_no+"_";

      for(var i = 0 ; i < tempAnswer.length ; i++ ){
        $(tempQuestionName+tempAnswer[i]).removeClass("showSolution");
      }
      this.solution = 0;
    },

    setUserAnswer: function(param){

      var tempSlideName    = "#slide_"+this.slidenumber;
      var tempQuestionName = "#"+this.slideid+" li#a"+this.major+"_"+this.q_no+"_";

      var tempChoiceNo = param.targetElement.attr("id").split("_")[2];

      var tempChoices = $(tempSlideName+' .choices');

      //tempUserAnswerを初期化
      var tempUserAnswer = new Array;
      for( var i = 0 ; i < this.data.choice_e.length ; i++ ){
        tempUserAnswer[i] = 0;
      }

      //tempUserAnswerに既存の値をコピー
      for( var i = 0 ; i < this.useranswer.length ; i++ ){
        tempUserAnswer[ this.useranswer[i]-1 ] = 1;
      }

      //チェックボックスのONOFF
      if( tempUserAnswer[tempChoiceNo-1] == 0 ){
        tempUserAnswer[tempChoiceNo-1] = 1;
      }
      else{
        tempUserAnswer[tempChoiceNo-1] = 0;
      }

      //最終的な値でユーザーの回答を記録
      this.useranswer = [];
      this.checked_num = 0;
      for( var i = 0 ; i < tempUserAnswer.length ; i++ ){
        if( tempUserAnswer[i] == 1 ){
          this.useranswer.push((i+1));
          this.checked_num++;
        }
      }

      //最終的な値で表示のONOFF
      if( tempUserAnswer[tempChoiceNo-1] == 0 ){
        param.targetElement.removeClass("checkbox_select");
      }
      else{
        param.targetElement.addClass("checkbox_select");
      }

      if( this.checked_num == 2 ){
        this.context.notify('answerd');
        //alert( String(this.useranswer) == this.answer ? "正解！": "不正解..." );
      }
      else{
        this.context.notify('thinking');
      }

    },

    revertUserAnswer: function(param){
      var tempSlideName    = "#"+this.slideid;
      var tempQuestionName = "li#q"+this.major+"_"+this.q_no+"_";

      for( var i = 0 ; i < this.data.choice_e.length ; i++ ){
        $(tempQuestionName+i).removeClass("checkbox_select");
      }
      for( var i = 0 ; i < this.useranswer.length ; i++ ){
        $(tempQuestionName+(this.useranswer[i])).addClass("checkbox_select");
      }

    },

    setTrueAnswer: function(){

      var tempSlideName    = "#slide_"+this.slidenumber;
      var tempQuestionName = "#"+this.slideid+" li#a"+this.major+"_"+this.q_no+"_";

      for( var i = 1 ; i <= tempSlideController.data.choice_e.length ; i++ ){
        if( this.answer != i ){
          $(tempQuestionName+i).removeClass("checkbox_select");
        }
        else{
          $(tempQuestionName+i).addClass("checkbox_select");
        }
      }

    }
  }
);

/* -----------------------------------------------------------------------------

ListeningSlideController_Qtype_d 

----------------------------------------------------------------------------- */
ListeningSlideController_Qtype_d = Class.extend(
  ListeningSlideController,
  {
    //プロパティ----------------------------------------------------------------
    //メソッド------------------------------------------------------------------
  }
);


/* -----------------------------------------------------------------------------

ListeningSlideController_Qtype_do

----------------------------------------------------------------------------- */
ListeningSlideController_Qtype_do = Class.extend(
  ListeningSlideController,
  {
    initialize: function(slideId, param) {

      //全スライド共通初期化処理
      this.commonInitialize(slideId,param);

      this.partQuestionCount = param.partQuestionCount;
      this.major      = this.data.major;
      this.q_no         = this.data.minor;

      this.answer       = this.data.correct_answer.split(",");
      this.useranswer   = "";

      this.checked_num  = 0;

      this.template = param.template;


      var tempSlideController = this;
      var tempSlideName = "#"+slideId;

      $("#"+this.slideid).ready(
        function(e){

          //Dropzone0(draggableの初期位置)
          var optDropzone0 = {
            tolerance: 'pointer',
            accept: '.draggable',
            hoverClass: 'dropzone_hover',
            drop: function(e, ui) {
              $(this).append(ui.draggable);
              tempSlideController.updateUserAnser();
            }
          }
          $(tempSlideName+' .dropzone0').droppable(optDropzone0);


          var optDropzone = {
            tolerance: 'pointer',
            accept: '.draggable',
            hoverClass: 'dropzone_hover',
            drop: function(e, ui) {

              var msg   = "<p>"+ ui.draggable.attr("id")
                              + " が "+this.id
                              + " へドロップされました</p>"
              //alert(msg);
              
              //ドロップは1個しか許さない
              if ($(this).children().length == 0) {
                $(this).append(ui.draggable);
                $(ui.draggable).css({
                  position: 'relative', left: 0, top: 0
                });
                tempSlideController.updateUserAnser();
              }
              else{
                ui.draggable.css({left: 0, top: 0});
              }
            }
          }
          $(tempSlideName+' .dropzone').droppable(optDropzone);


          var optDraggable = {
            //opacity: 0.5,
            stop: function(e, ui) {
              $(e.target).css({
                position: 'relative', left: 0, top: 0,
                cursor:"pointer"
              });
            }
          }
          $(tempSlideName+' .draggable').draggable(optDraggable);

        }
      );
    },

    play: function(){
      //外部からSlide(Question)を開始するメソッドです
      this.hideQuestion();

      //Resultを更新
      r.seek(this.partQuestionCount);

      //既存の成績の書き戻し
      this.showsolution = r.saw_solution();
      this.useranswer = r.user_answer();
      if( this.useranswer != "" ){
        this.revertUserAnswer();
      }

      this.playQuestionSound();

      //Timerエリアの表示
      this.showTimer();

      //タイマー停止
      this.context.components["timer"].pauseTimer();

    },

    stop: function(){
      //外部からSlide(Question)を終了するメソッドです

      //タイマー停止
      this.context.components["timer"].pauseTimer();

      this.stopQuestionSound();

      //成績・進捗を更新
      this.setCurrentResult();
    },

    dispQuestion: function() {
      $("#"+this.slideid+" .user_answer_area").show();

      this.context.notify('thinking');

      //既存の成績をチェック
      this.updateUserAnser();

      //タイマー起動
      this.context.components["timer"].startTimer();
      this.context.components["timer"].show();

    },

    hideQuestion: function() {
      $("#"+this.slideid+" .user_answer_area").hide();
    },

    toggleSolution: function(){
      
      if ( $("#"+this.slideid+" .user_answer_area").css("display") != "none" ){
        this.hideQuestion();
        $("#"+this.slideid+" .true_answer_area").show();
      }
      else{
        $("#"+this.slideid+" .true_answer_area").hide();

        this.dispQuestion();
      }
      this.context.notify('answerd');

    },

    setUserAnswer: function(param){
    },


    revertUserAnswer: function(){
      var tempSlideName = "#"+this.slideId;

      var tempAnswer  = String(r.user_answer());
      tempAnswer = tempAnswer.split(",");
      for( var i = 0 ; i < tempAnswer.length ; i++ ){
        $(tempSlideName+' #dropzone_q'+this.major+'_'+this.q_no+'_'+(i+1) ).append($("#draggable_q"+this.major+'_'+this.q_no+"_"+tempAnswer[i] ));
      }

    },
    
    setTrueAnswer: function(){
    },

    updateUserAnser: function(){

      var tempSlideController = this;
      var tempSlideName    = "#"+this.slideid;
      var tempUserAnser = new Array();
      var tempDroppableIdName = "dropzone_q"+this.major+"_"+this.q_no+"_";
      var tempDraggableIdName = "draggable_q"+this.major+"_"+this.q_no+"_";

      //dropzoneをチェック
      for( var i = 1 ; i <= this.answer.length ; i++ ){
        var tempDropZoneID = tempSlideName+' #'+tempDroppableIdName+i+' .draggable';
        if( $(tempDropZoneID).attr("id") ){
          tempUserAnser.push(String($(tempDropZoneID).attr("id")).split("_")[3]);
        }
      }
      
      if( tempUserAnser.length == this.answer.length){

        this.context.notify('answerd');

        if( String(tempUserAnser) == String(this.answer)){
          //alert("正解！ "+tempUserAnser);
        }
        else{
          //alert("不正解... "+tempUserAnser+" != "+this.answer);
        }

      }
      else{
        this.context.notify('thinking');
      }

      this.useranswer = String(tempUserAnser);

    }

  }
);


/* -----------------------------------------------------------------------------

ListeningSlideController_Qtype_ds

----------------------------------------------------------------------------- */
ListeningSlideController_Qtype_ds = Class.extend(
  ListeningSlideController,
  {
    //プロパティ----------------------------------------------------------------
    //メソッド------------------------------------------------------------------
  }
);


/* -----------------------------------------------------------------------------

ListeningSlideController_PartEnd

----------------------------------------------------------------------------- */
ListeningSlideController_PartEnd = Class.extend(
  ListeningSlideController,
  {
    //プロパティ----------------------------------------------------------------
    //メソッド------------------------------------------------------------------
    initialize: function(slideId,param) {

      //全スライド共通初期化処理
      this.commonInitialize(slideId,param);

    },

    play: function(){

      //タイマー停止
      this.context.components["timer"].pauseTimer();

      //Timerエリアの非表示
      this.hideTimer();

    },

    stop: function(){
    }

  }
);

/* -----------------------------------------------------------------------------

ListeningSlideController_examOutro

----------------------------------------------------------------------------- */
ListeningSlideController_examOutro = Class.extend(
  ListeningSlideController,
  {
    //プロパティ----------------------------------------------------------------
    //メソッド------------------------------------------------------------------
    initialize: function(slideId,param) {

      //全スライド共通初期化処理
      this.commonInitialize(slideId,param);

    },
    play: function(){

      //タイマー停止
      this.context.components["timer"].pauseTimer();

      //Timerエリアの非表示
      this.hideTimer();

      this.setFinish();
    },

    stop: function(){
    }

  }
);



