/* -----------------------------------------------------------------------------

toeflContext.js uses:
  context.js
  
------------------------------------------------------------------------------- */

var ToeflContext = Class.extend( Context, {

  initialize: function ( part, isLastPart, nextUrl, pauseTestUrl ) {

    this.parent();

    this.part       = part;
    this.isLastPart = isLastPart;
    this.nextUrl    = nextUrl;
    this.pauseTestUrl = pauseTestUrl;

    this.questionIdPrefix = "question";
    this.presentationIdPrefix = "passage";

    this.afterSendingResultMethod;

  },

  start: function () {

    $("#container").show();
    this.parent();

  },

  questionCue: function (num) {

    var id = this.questionIdPrefix + num;
    this.setPresentationSlideNum(id);
    this.projector.goto(id);
    this.change(this.questionState);

  },

  setPresentationSlideNum: function ( id ) {

    for ( var i in this.projector.slides ) {

      if ( this.projector.slides[i].attr("id").match(this.presentationIdPrefix ) ) {

        this.projector.empty();
        this.projector.currentSlideNum = i;
        this.projector.push();

      }

      if ( this.projector.slides[i].attr("id").match(id) ) {

        break;

      }

    }

  },

  goNextUrl: function () {

    window.location.href = this.nextUrl;

  },

  goPauseTestUrl: function () {

    window.location.href = this.pauseTestUrl;

  },

  setExperienceMode: function () {

    this.isExperienceMode = true;

  },

  setResult: function () {

    if ( this.isExperienceMode ) {

      this.afterSendingResultMethod();
      return true;

    }

    this.projector.openWindow("sendingResult", true, 400, 300);

    if ( this.currentSlide.setResult() ) {

      this.afterSendingResultMethod();

    }
    else {

      this.projector.openWindow("sendingResultFailure", true, 400, 300);

    }

  }

});
