$(document).ready(function(){
var k = Karma({
audio: [{'name':'correct','file':'correct.wav'},
{'name':'incorrect','file':'incorrect.wav'}
]});
k.ready(function(){
var i,j;
var totalCounter;
var correctCounter;
var currentQuestion;
var TOTAL_QUES = 6;
var flag_correct;
var randPositions = [];
var check_num;
var variableName = new Array('x','p','y','x','x','r');
var perPack = new Array('16','80','25','30','15','70');
var quantity = new Array('4','1','2','3','2','1');
var finishedQty = new Array('8','30','16','7','7','22');
var answers = new Array('58','50','34','97','37','48');
var scoreboard = $('#score_box').scoreboard({'layout':'horizontal',
'winningScore': TOTAL_QUES});
var genRandPosition=function (){
randPositions[0] = k.rand(0,TOTAL_QUES-1);
for(i=1; i ');
//$('#left-side').html(' ');
$('#rightBack').css({'background':'url(assets/image/ques'+currentQuestion+'.png)'});
$('.bgCalculation').html('').append('
');
$('.bgCalculation').append('
');
if(currentQuestion ===3 || currentQuestion === 4){
sign = '+';
}
else{
sign = '-';
}
for( i = 0; i< quantity[currentQuestion]; i++){
$('#textQues1').append(variableName[currentQuestion]);
$('#textQues2').append(' ');
if(i != quantity[currentQuestion]-1){
$('#textQues1').append('+');
$('#textQues2').append('+');
}
else{
if(parseInt(quantity[currentQuestion]) === 1){
$('#textQues1').append(sign+''+finishedQty[currentQuestion]);
$('#textQues1').append(' = ').append(variableName[currentQuestion]);
$('#textQues1').append(sign+''+finishedQty[currentQuestion]);
$('#textQues2').append(sign+''+finishedQty[currentQuestion]);
$('#textQues2').append(' = ').append(' ');
$('#textQues2').append(sign+''+finishedQty[currentQuestion]);
}
else{
$('#textQues1').append(sign+''+finishedQty[currentQuestion]);
$('#textQues1').append(' = ').append(quantity[currentQuestion]+' * '+variableName[currentQuestion]);
$('#textQues1').append(sign+''+finishedQty[currentQuestion]);
$('#textQues2').append(sign+''+finishedQty[currentQuestion]);
$('#textQues2').append(' = ').append(quantity[currentQuestion]+' *'+' ');
$('#textQues2').append(sign+''+finishedQty[currentQuestion]);
}
}
$("input#text1").focus();
}
foucs_blur();
}
};
function game_start(){
$('#gameOver').hide();
$('#linkCheck').show();
$('#section').removeClass('backOpaque');
genRandPosition();
next_question();
}
function game() {
totalCounter = 0;
correctCounter = 0;
$('#section').html('').append('
');
$('#section').append('
');
$('#right-side').append('
');
$('#right-side').append('
');
$('#help').hide();
$('#linkCheck').hide();
$('#gameOver').hide();
}
game();
var delay_nextQues = function(){
document.delayForm.delayval.value = 1;
next_question();
};
var delay_gameOver = function(){
document.delayForm.delayval.value = 1;
$('#section').addClass('backOpaque');
$('#linkCheck').hide();
$('#gameOver').show();
};
var check_answer = function(){
if(check_num === 0){
var textVal = $('#text1').val();
if(textVal === perPack[currentQuestion]){ // first one is correct
k.audio.correct.play();
$('.bgCalculation').append('
');
$('.bgCalculation').append('
');
$('#textQues3').append(' = ').append(' ');
$('#text1').attr("disabled", true);
$('.blankBoxes').css({'padding':'0'}).html(perPack[currentQuestion]);
check_num++;
$("input#text2").focus();
foucs_blur();
}
else{
k.audio.incorrect.play();
flag_correct = 0;
}
}
else{
textVal = $('#text2').val();
//if(textVal === perPack[currentQuestion] * quantity[currentQuestion]){
if(textVal === answers[currentQuestion]){
k.audio.correct.play();
if(flag_correct === 1){
scoreboard.scoreboard('inc');
correctCounter++;
}
scoreboard.scoreboard('incTotal');
totalCounter++;
t=setTimeout(function(){delay_nextQues();},1000);
}
else{
flag_correct = 0;
k.audio.incorrect.play();
}
}
};
function foucs_blur(){
$('input[type="text"]')
.focus(function() {
$(this).removeClass('incorrect').addClass("focus");
})
.blur(function() {
$(this).removeClass("focus");
})
.keypress(function(event) {
if(event.which === 13){
check_answer();
}
});
$('#linkCheck').click(function(){
check_answer();
});
}
$('#linkStart').click(function(){
game_start();
});
$('#linkPlayAgain').click(function(){
scoreboard.scoreboard('reset');
game_start();
});
$('#linkHelp').click(function(){
$('#help').slideDown(2000);
})
.mouseout(function(){
$('#help').slideUp(2000);
});
}); //end of k.ready
}); //end of document.ready