var IQTest = {

  _q_num: 1,
  _q_total: 10,

  init: function() {
    if (typeof sc_sentinel == 'function') {
      if (!sc_sentinel({cookie_name:'IQTest_completed'})) {
        return;
      }
    }
    else if (Get_Cookie('IQTest_completed') == 'true') {
      return;
    }

    var d = new Date();
    var today = $('<span></span>').attr({'id': 'today'}).text(d.getDate() + '-' + (d.getMonth()+1) + '-' + d.getFullYear() + ' ');
    $('#highest_score_msg').prepend(today);

    $('#inputzone').hide();
    $('#question_index').show();
    $('#container').removeClass('imagestep1').addClass('imagestep0 imagestep_pre1');
    $('#question_zone .answers a').click(function(e) {e.preventDefault(); IQTest.next();});

    // hide terms & conditions for non US contries, except es_ES, sv_SE and de_DE
    if ( (! $('body').hasClass('en_US')) &&
				 (! $('body').hasClass('es_US')) &&
				 (! $('body').hasClass('es_ES')) &&
				 (! $('body').hasClass('en_CA')) &&
				 (! $('body').hasClass('sv_SE')) &&
				 (! $('body').hasClass('da_DK')) &&
				 (! $('body').hasClass('de_DE')) &&
				 (! $('body').hasClass('nl_NL')) &&
				 (! $('body').hasClass('et_EE'))
       ) {
      $('#tnc').hide();
    }

    if ($('body').hasClass('nl_NL')) {
      $('#subtitle1').show();
    }

    // DE only 5 questions
    if ($('body').hasClass('de_DE')) {
      IQTest._q_total = 5;
    }
  },

  startTest: function() {
    /* hide all question divs */
    for(var i = 1; i <= 10; i++ ) {
      $('.q' + i).hide();
    }

    $('.q' + this._q_num).show();

    $('#question_index').hide();
    $('#question_zone').fadeIn('slow');

    $('#container').removeClass('imagestep_pre1').addClass('imagestep_pre2');
  },

  next: function() {
    this._q_num++;

    /* hide all question divs */
    for(var i = 1; i <= this._q_total; i++ )
      $('.q' + i).hide();

    $('#question_zone').show();
    $('.q' + this._q_num).show();

    if (this._q_num > this._q_total) {
      this.endTest();
    }
    else {
      $('#question_zone').attr('class', 'q'+this._q_num);
    }
  },

  endTest: function() {
    $('#question_zone').hide();
		if ($('body').hasClass('en_NZ')) {
      this.end();
      return;
    }

    $('#container').removeClass('imagestep_pre2').addClass('imagestep_pre3');

		$('#question_gender').fadeIn('slow');
  },

  end: function() {
    $('#operatorlist').val($('#question_operatorlist').val());
    $('#question_gender').hide();
    $('#inputzone').fadeIn('slow');
    $('#container').removeClass('imagestep0 imagestep_pre1 imagestep_pre2 imagestep_pre3').addClass('imagestep1');
    Set_Cookie('IQTest_completed', 'true');
    // show terms & conditions
    $('#tnc').fadeIn('slow');

    if (typeof (operator_selector) == 'object') {
      operator_selector.handle();
    }
  },

  checkTerms: function(message) {
    if (! $('#terms')) return true;
    if ($('#terms').attr('type') == 'hidden') return true;
    if (! $('#terms').attr('checked')) {
      // highlight the checkbox
      $('#term_warn_box').css('visibility', 'visible');
      $('#term_cb_wrap').addClass("term_cb_highlight");
			alert(message);
			return false;
    }
    return true;
  }
};

landingControlHolder['precontroller'] = IQTest;

top.window.moveTo(0,0);
if (document.all) {
	top.window.resizeTo(screen.availWidth,screen.availHeight);
}
else if (document.layers||document.getElementById) {
	if (top.window.outerHeight<screen.availHeight||top.window.outerWidth<screen.availWidth){
		top.window.outerHeight = screen.availHeight;
		top.window.outerWidth = screen.availWidth;
	}
};
