//SCREEN
var windowW = window.innerWidth;
var windowH = window.innerHeight;
function init(){
	
	
	
	
	
	setInterval(moves,0.01);
	
	$('noweasy').addEventListener('click',stopeasy,false);
	$('now').addEventListener('click',stop,false);
	$('btn-easy-back').addEventListener('click',abdication,false);
	$('btn-hard-back').addEventListener('click',abdication,false);
	$('delete').addEventListener('click',removeData,false);
	 
	b0.style.top = (windowH/2-10)+"px";
	b0.style.left = (windowW/2-10)+"px";
	b1.style.top = (windowH/2-8)+"px";
	b1.style.left = (windowW/2-8)+"px";
	b2.style.top = (windowH/2-6)+"px";
	b2.style.left = (windowW/2-6)+"px";
	
	nb0.style.top = (windowH/2-50)+"px";
	nb0.style.left = (windowW/2-50)+"px";
	nb1.style.top = (windowH/2-50)+"px";
	nb1.style.left = (windowW/2-50)+"px";
	nb2.style.top = (windowH/2-50)+"px";
	nb2.style.left = (windowW/2-50)+"px";
		
}
window.addEventListener('load', init, false);




var nb0 = document.querySelector('#nb0');
var nb1 = document.querySelector('#nb1');
var nb2 = document.querySelector('#nb2');

var r = 0;                  //C forgatása
var k=10;                   //kisbetűk kezdeti mérete
var o = 1.00;               //kisbetűk kezdeti átlátszósága
var u = 0.00;               //nagybetűk átlátszósága
var f = 0;                  //nagybetűk kezdeti mérete
var c =0;                   //C betű piros színe (kezdetben)

function rerotate(){			//C forgatása
	
	if(nb2.style.transform != "rotate(60deg)"){
		r++;
		nb2.style.transform = "rotate("+r+"deg)";
		
	}
}



function recolor(){			// C szinezése
	if(nb2.style.color !="rgb(255, 0, 0)"){
		c=c+1;
		nb2.style.color = "rgb("+c+",0,0)";
	}
}

function refontsize(){															// nagybetűk méretezése
	if(document.getElementById('nb0').style.fontSize != '500%' && 
		document.getElementById('nb1').style.fontSize != '500%' && 
		document.getElementById('nb2').style.fontSize != '500%'){
		f+=2;
		document.getElementById('nb0').style.fontSize = f+"%";
		document.getElementById('nb1').style.fontSize = f+"%";
		document.getElementById('nb2').style.fontSize = f+"%";
	
	}else if(nb2.style.color !="rgb(255, 0, 0)"){
		c=c+2;
		nb2.style.color = "rgb("+c+", 0, 0)";
	}else if(nb2.style.color =="rgb(255, 0, 0)"){
		rerotate();
		
	}
}


function reopacityABC(){												// nagybetűk átlátszóságának állítása
	 if(document.getElementById('nb0').style.opacity != '1.00' && 
		document.getElementById('nb1').style.opacity != '1.00' && 
		document.getElementById('nb2').style.opacity != '1.00'){
		u+=1.0;
		document.getElementById('nb0').style.opacity = u;
		document.getElementById('nb1').style.opacity = u;
		document.getElementById('nb2').style.opacity = u;
	
	}
}

function reopacity(){													// kisbetűk átlátszósága
	 if(document.getElementById('b0').style.opacity != '0.00' && 
		document.getElementById('b1').style.opacity != '0.00' && 
		document.getElementById('b2').style.opacity != '0.00'){
		o-=0.001;
		document.getElementById('b0').style.opacity = o;
		document.getElementById('b1').style.opacity = o;
		document.getElementById('b2').style.opacity = o;
		
	}
}
	
		
var b0 = document.querySelector('#b0');
var b1 = document.querySelector('#b1');
var b2 = document.querySelector('#b2');

var b0x = 100;                       // kisbetűk x,y koordinátája kezdetben
var b0y = 100;                       // kisbetűk x,y koordinátája kezdetben
                                     // kisbetűk x,y koordinátája kezdetben
var b1x = 100;                       // kisbetűk x,y koordinátája kezdetben
var b1y = 100;                       // kisbetűk x,y koordinátája kezdetben
                                     // kisbetűk x,y koordinátája kezdetben
var b2x = 100;                       // kisbetűk x,y koordinátája kezdetben
var b2y = 100;                       // kisbetűk x,y koordinátája kezdetben
currentd = 0;                        // kisbetűk kezdeti forgatás kezdetben
	

function moves(){	
 
	if(b0x >= 0.1 && b0y  >= 0.1 && b1x >= 0.1 && b1y  >= 0.1 && b2x >= 0.1 && b2y  >= 0.1 || 
	document.getElementById('b0').clientWidth != 0 && document.getElementById('b0').clientHeight != 0 &&
	document.getElementById('b1').clientWidth != 0 && document.getElementById('b1').clientHeight != 0 &&
	document.getElementById('b2').clientWidth != 0 && document.getElementById('b2').clientHeight != 0){
		b0x -= 0.1;
		b0y -= 0.1;
		
		b1x -= 0.1;
		b1y -= 0.1;
		
		b2x -= 0.1;
		b2y -= 0.1;
		currentd++;
		b0.style.transform="rotate("+currentd+"deg) translate("+b0x+"px,"+b0y+"px)";
		b1.style.transform="rotate("+currentd+"deg) translate("+b1x+"px,"+b1y+"px)";
		b2.style.transform="rotate("+currentd+"deg) translate("+b2x+"px,"+b2y+"px)";
		
		reopacity();
		
		k-=0.01;
		document.getElementById('b0').style.width = k+"px";
		document.getElementById('b0').style.height = k+"px";
		document.getElementById('b1').style.width = k+"px";
		document.getElementById('b1').style.height = k+"px";
		document.getElementById('b2').style.width = k+"px";
		document.getElementById('b2').style.height = k+"px";
	}else{
		refontsize();
	}
}



//új játék

document.querySelector('#btn-newgame').addEventListener ('click', function () {
  document.querySelector('#newgame').className = 'current';
  document.querySelector('[data-position="current"]').className = 'left';
});
document.querySelector('#btn-newgame-back').addEventListener ('click', function () {
  document.querySelector('#newgame').className = 'right';
  document.querySelector('[data-position="current"]').className = 'current';
});

var myIntervaleasy;

//Szint : Easy
document.querySelector('#btn-easy').addEventListener ('click', function () {
  document.querySelector('#easy').className = 'current';
  document.querySelector('[data-position="current"]').className = 'left';
  myIntervaleasy = setInterval(charmove, 200);
  
});

document.querySelector('#btn-easy-back').addEventListener ('click', function () {
  document.querySelector('#easy').className = 'right';
  document.querySelector('#newgame').className = 'right';
  document.querySelector('[data-position="current"]').className = 'current';
});



//Szint : Hard
document.querySelector('#btn-hard').addEventListener ('click', function () {
  document.querySelector('#hard').className = 'current';
  document.querySelector('[data-position="current"]').className = 'left';
});
document.querySelector('#btn-hard-back').addEventListener ('click', function () {
  document.querySelector('#hard').className = 'right';
  document.querySelector('#newgame').className = 'right';
  document.querySelector('[data-position="current"]').className = 'current';
});


//TOP
document.querySelector('#btn-top').addEventListener ('click', function () {
	names = JSON.parse(localStorage.getItem('locnamepoint') || "[]");
	point = JSON.parse(localStorage.getItem('locpoint') || "[]");
	char = JSON.parse(localStorage.getItem('locchar') || "[]");
	document.querySelector('#name').innerHTML = names.join ('<br>');
	document.querySelector('#pont').innerHTML = point.join ('<br>');
	//document.querySelector('#char').innerHTML = char.join ('<br>');
	
  document.querySelector('#top').className = 'current';
  document.querySelector('[data-position="current"]').className = 'left';
});

document.querySelector('#delete').addEventListener ('click', function () {
	names = JSON.parse(localStorage.getItem('locnamepoint') || "[]");
	point = JSON.parse(localStorage.getItem('locpoint') || "[]");
	char = JSON.parse(localStorage.getItem('locchar') || "[]");
	document.querySelector('#name').innerHTML = names.join ('<br>');
	document.querySelector('#pont').innerHTML = point.join ('<br>');
	//document.querySelector('#char').innerHTML = char.join ('<br>');
});


document.querySelector('#btn-top-back').addEventListener ('click', function () {
  document.querySelector('#top').className = 'right';
  document.querySelector('[data-position="current"]').className = 'current';
});


//Segítség
document.querySelector('#btn-help').addEventListener ('click', function () {
  document.querySelector('#help').className = 'current';
  document.querySelector('[data-position="current"]').className = 'left';
});
document.querySelector('#btn-help-back').addEventListener ('click', function () {
  document.querySelector('#help').className = 'right';
  document.querySelector('[data-position="current"]').className = 'current';
});

//Kilépés
document.querySelector('#btn-exit').addEventListener ('click', function () {
  window.close();
});

	
	
//vége
function abdication(){
	document.getElementById('ido').innerHTML=ido;
	ido=0;
}

function vege(){
	/*document.getElementById('words').style.visibility = "hidden";
	document.getElementById('add').style.visibility = "hidden";
	document.getElementById('btn-top').style.visibility = "hidden";*/
	
	if(document.querySelector('#hard').className == 'current'){
		document.querySelector('#hard').className = 'right';
		document.querySelector('#newgame').className = 'right';
		document.querySelector('[data-position="current"]').className = 'current';
		document.querySelector('#words').value = "";
	}else if(document.querySelector('#easy').className == 'current'){
		document.querySelector('#easy').className = 'right';
		document.querySelector('#newgame').className = 'right';
		document.querySelector('[data-position="current"]').className = 'current';
		document.querySelector('#wordseasy').value = "";
	}
	
	
	
	var nev = prompt('Neved:','Név?');
	names.push(nev);
	
	var data1 = z;
	point.push(data1);
	
	var ch = document.getElementById("chars").innerHTML;
	//char.push(ch);
	
	localStorage.setItem('locpoint', JSON.stringify(point));  
	localStorage.setItem('locnamepoint', JSON.stringify(names));
	localStorage.setItem('locchar', JSON.stringify(char));
	
	window.location.reload();
}