var Word={};
Word.i=0;
Word.id=0
Word.concateword='';
Word.wordArray=[];
Word.seconds = 180;
Word.width=0;
Word.marks=0;
 
$(document).ready(function()
{
	$(".se-pre-con").fadeOut("slow");
	setTimeout(function(){
	document.body.style.backgroundImage="url(images/Cover.png)";
	document.getElementById('coverpage').style.display="block";
	document.getElementById('gamepage').style.display="none";
	document.getElementById('homeDiv').style.visibility="hidden ";
	document.getElementById('prid').style.visibility="hidden";
	
	Word.setImage();
	Word.createMulakshareDiv(row1,14);
	Word.createMulakshareDiv(row2,15);
	Word.createMulakshareDiv(row3,11); 
	Word.createMatraDiv(matrarow1);
	Word.createMatraDiv(matrarow2);
	Word.createMatraDiv(matrarow3);
	Word.createMatraDiv(matrarow4);


	document.getElementById('list').innerHTML=Word.HardcoadedData[0]
	document.getElementById('list').style.color='#1bc2ca';
	$('#middlespace').droppable({drop:Word.setWords});
},200);
});
//playGame called on play btn
Word.playGame=function()
{
	document.body.style.backgroundImage="url('images/BG.png')";
	document.getElementById('gamepage').style.display="block";
	document.getElementById('coverpage').style.display="none";
	document.getElementById('homeDiv').style.visibility="visible";
	document.getElementById('prid').style.visibility="visible";
	document.getElementById('middlespace').style.visibility="visible";
	document.getElementById('prid').style.visibility="visible";
	setInterval(function() 
	{
		Word.countDown();
		if(Word.width==100)
		{
			document.getElementById('paraid').innerHTML=Word.HardcoadedData[1];
			document.getElementById('myModal').style.display="block"; 
		}
		if(Word.width==85)
			$('#pbarid').addClass("progress-bar-danger");
	},1100);
}
//set all images//
Word.setImage=function()
{
	document.getElementById('logo').src="images/logo.png";
	document.getElementById('play').src="images/Play.png";
	document.getElementById('home').src="images/Home.png";
	document.getElementById('done').src="images/Done.png";
	document.getElementById('Next').src="images/Next.png";
	document.getElementById('Undoo').src="images/Undoo.png";
	document.getElementById('modaljoker').src="images/joker_04.png";
}
//creates mulakshare div//
Word.createMulakshareDiv=function(parentdiv,cnt)
{
	var divElement,txtElement;
	for(var j=1;j<=cnt;j++)
	{
		divElement=document.createElement('span');
		divElement.setAttribute('id','box'+Word.i);
		divElement.setAttribute('class','spancls');
		divElement.innerHTML=Word.BasicWord[Word.i];
		$(divElement).draggable(
		{	
			start: function()
				{	$(this).data("pos",$(this).position());
				},
			revert:'invalid',
			helper:"clone"
		});	
		parentdiv.append(divElement);
		Word.i++;
	}
}
//creates kana-matra div//
Word.createMatraDiv=function(parentdiv)
{
	var divElement,txtElement,paraElement;
	for(var j=1;j<=3;j++)
	{
		divElement=document.createElement('span');
		divElement.setAttribute('id','matra'+Word.id);
		divElement.setAttribute('class','centercls matracls col-sm-3 col-lg-3 col-md-3 col-xs-3');
		divElement.innerHTML=Word.UkarWords[Word.id];
		$(divElement).draggable(
		{	helper:"clone",
			revert:'invalid'
		});
		parentdiv.append(divElement);
		Word.id++;
	}
}
// set text on middlespace//
Word.setWords=function(event,ui)
{
	var str=$(ui.draggable).text();
	Word.concateword=Word.concateword.concat(str);
	$('#middlespace').text(Word.concateword);
}
//checks word is right or wrong//
Word.checkWord=function()
{
	var shabd='';
	shabd=document.getElementById('middlespace').innerHTML;
	if(!(Word.wordArray.includes(shabd)))
	{
		if(Word.wlistl3.includes(shabd))
		{
			Word.marks=Word.marks + 10;
			document.getElementById('playsound').src="Sounds/correct.mp3";
			document.getElementById('playsound').play();
			document.getElementById('joker').style.display="block";
			document.getElementById('joker').src="images/joker_02.png";
			Word.wordArray.push(shabd);
			//document.getElementById('marksDiv').innerHTML=Word.marks;
			 setTimeout(function()
			{
				document.getElementById('joker').style.display="none";
			},1200); 
			var mybr = document.createElement('br');
			list.appendChild(mybr);
			document.getElementById('list').style.color='#1bc2ca';
			document.getElementById('list').append(shabd);
		}
		else
		{
			document.getElementById('playsound').src="Sounds/wrong.mp3";
			document.getElementById('playsound').play();
			document.getElementById('joker').style.display="block";
			document.getElementById('joker').src="images/joker_03.png";
			 setTimeout(function()
			{
				document.getElementById('joker').style.display="none";
			},1200); 
		}
	}
	else
	{
		document.getElementById('playsound').src="Sounds/wrong.mp3";
		document.getElementById('playsound').play();
		document.getElementById('joker').style.display="block";
		document.getElementById('joker').src="images/joker_03.png";
		 setTimeout(function()
		{
			document.getElementById('joker').style.display="none";
		},1200); 
	}
}
//called on clear btn//
Word.clearWord=function()
{
	document.getElementById('middlespace').innerHTML="";
	Word.concateword='';
}
//called on undoo btn//
Word.undooWord=function()
{
	var shabd='';
	var word='';
	var undooword='';
	shabd=document.getElementById('middlespace').innerHTML;
	word=shabd.split('');
	word.splice(word.length-1,1);
	for(i=0;i<word.length;i++)
	{
		undooword=undooword.concat(word[i]);
	}
	document.getElementById('middlespace').innerHTML=undooword;
	Word.concateword=undooword;
}
//increases the width of progress bar //
Word.countDown=function()
{
	Word.width++; 
    document.getElementById("pbarid").style.width = Word.width + '%';  
}
//play game again//
Word.playAgain=function()
{
	Word.width=0;
	Word.wordArray.length=0;
	Word.concateword='';
	document.getElementById('myModal').style.display="none"; 
	document.getElementById("pbarid").style.width = Word.width + '%';
	document.getElementById('middlespace').innerHTML='';
	$('#pbarid').removeClass("progress-bar-danger");	
	$('#list').empty();
	document.getElementById('list').innerHTML=Word.HardcoadedData[0];
}