/*

*/

var viQuiz = Class.create();

viQuiz.prototype =
{
	parentID:null,
	parentObj:null,
	questionClass:"quizVraag",
	quizLoaderProgress:"quizLoaderProgress",
	quizLoaderProgressObj:null,
	questionsArray:null,
	quizSubmitObj:null,
	quizInit:false,
	intervalSeconds:10,
	intervalID:null,
	quizQuestionIndex:0,
	timerID:null,
	timerSeconds:null,
	timerClipWidth:0,
	timerCurrentSeconds:0,
	progressBarWidth:417,
	quizFormId:null,

	initialize: function(pId,intervalSeconds,quizFormId)
	{
		if(typeof pId == "string")
		{
			if(pId!="")
			{
				if($(pId))
				{
					this.parentID=pId;
					this.parentObj=$(pId);

					if(typeof intervalSeconds == "number")
					{
						intervalSeconds=parseInt(intervalSeconds);
						if(intervalSeconds>0)
						{
							this.intervalSeconds=intervalSeconds;
						}

					}
					this.quizInit= true;
					this.quizInit=this.getProgressBar();
					this.quizFormId = quizFormId;
				}
			}
		}
	},

	getProgressBar:function()
	{
		if(this.quizInit)
		{
			var dummy=this.parentObj.getElementsByClassName(this.quizLoaderProgress);
			if(dummy)
			{
				if(dummy.length>0)
				{
					var t=dummy[0];
					t.id=this.parentID + "_" + this.quizLoaderProgress;

					if($(this.parentID + "_" + this.quizLoaderProgress))
					{
						this.quizLoaderProgressObj=$(this.parentID + "_" + this.quizLoaderProgress);
						this.quizLoaderProgressObj.style.width="0px";
						this.quizLoaderProgressObj.style.display="block";
						return true;
					}

				}
			}
		}
		return false;
	},

	start:function()
	{;
		if(this.quizInit)
		{
			//this.intervalID=new PeriodicalExecuter(this.quizCallback.bind(this), this.intervalSeconds);

			this.timerSeconds=Math.floor(this.progressBarWidth / this.intervalSeconds);
			this.timerClipWidth=this.timerSeconds;

			this.timerID=new PeriodicalExecuter(this.updateTimer.bind(this), 1);
		}
	},

	updateTimer:function()
	{
		var currentW=parseInt(this.quizLoaderProgressObj.style.width);
		currentW+=this.timerClipWidth;

		this.quizLoaderProgressObj.style.width=currentW + "px";

		this.timerCurrentSeconds++;


		var ww=this.timerCurrentSeconds % this.intervalSeconds;

		if(ww == 0 )
		{
			this.quizLoaderProgressObj.style.width=this.progressBarWidth + "px";
			this.submitQuestion();
		}

	},

	submitQuestion:function() {
			this.timerID.stop();
			var all = document.getElementsByName('answerid');
			for(i=0;i<all.length;i++) {
				if (!all[i].checked) {all[i].disabled = true;}
			}
			var elForm = document.getElementById(this.quizFormId);
    	elForm.submit();
	}
}