if (screen.width > 480) {
	device= 'pc'
}
else {
	device= 'mobile'
}

function toTop() {
	setTimeout("window.scrollTo(0,1)",950)
}
function toTopFast() {
	setTimeout("window.scrollTo(0,1)",1)
}

function setCursor() {
	document.forms[0][0].focus()
	getProblem()
} 


function suitCSS() {
	if (device == 'pc') {
		document.body.setAttribute('id','pc')
	}
	else {
		document.body.setAttribute('id','mobile')
	}
}

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}


function addClickEvent(func, el) {
  var oldonclick = el.onclick;
  if (typeof el.onclick != 'function') {
    el.onclick = func;
  } else {
    el.onclick = function() {
      if (oldonclick) {
        oldonclick();
      }
      func();
    }
  }
}


function addTouchStartEvent(func, el) {
  var oldontouchstart = el.ontouchstart;
  if (typeof el.ontouchstart != 'function') {
    el.ontouchstart = func;
  } else {
    el.ontouchstart = function() {
      if (oldontouchstart) {
        oldontouchstart();
      }
      func();
    }
  }
}

function addOrientationEvent(func) {
  var oldonorientation = window.onorientationchange;
  if (typeof window.onorientationchange != 'function') {
    window.onorientationchange = func;
  } else {
    window.onorientationchange = function() {
      if (oldonorientation) {
        oldonorientation();
      }
      func();
    }
  }
}


function resetScore() {
	deleteCookie('score')
	document.getElementById('correct').innerHTML= 0
	document.getElementById('incorrect').innerHTML= 0
}


document.getElementsByClassName = function(cl) {
	var retnode = [];
	var myclass = new RegExp('\\b'+cl+'\\b');
	var elem = this.getElementsByTagName('*');
	for (var i = 0; i < elem.length; i++) {
		var classes = elem[i].className;
		if (myclass.test(classes)) retnode.push(elem[i]);
	}
	return retnode;
}


function checkOrientation() {

  var orientation = window.orientation

  switch(orientation) {

    case 0:

        document.body.setAttribute("class","portrait")
		document.getElementById('k02').style.display= 'none'
		document.getElementById('k0').style.display= 'block'

        break  

    case 90:

        document.body.setAttribute("class","landscape")
		document.getElementById('k0').style.display= 'none'
		document.getElementById('k02').style.display= 'block'

        break

    case -90: 

        document.body.setAttribute("class","landscape")
		document.getElementById('k0').style.display= 'none'
		document.getElementById('k02').style.display= 'block'		

        break
  }
}

function setSettings(){
	
	var level= document.getElementById('level').value
	
	var addition= document.getElementById('addition').checked
	addition == true ? addition= '_addition' : addition= ''
	
	var substraction= document.getElementById('substraction').checked
	substraction == true ? substraction= '_substraction' : substraction= ''
	
	var multiplication= document.getElementById('multiplication').checked
	multiplication == true ? multiplication= '_multiplication' : multiplication= ''
	
	var division= document.getElementById('division').checked
	division == true ? division= '_division' : division= ''
	
	var power= document.getElementById('power').checked
	power == true ? power= '_power' : power= ''
	
	var root= document.getElementById('root').checked
	root == true ? root= '_root' : root= ''
	
	var cookiestring= level + '#' + addition + substraction + multiplication + division + power + root
	
	setCookie('settings', cookiestring, year, '/calc/')
}

function homeFadeIn(){
	setTimeout("document.getElementById('home').style.opacity=1",0)	
}
function menuFadeIn(){
	setTimeout("document.getElementById('menu').style.opacity=1",0)	
}
function tipsFadeIn(){
	setTimeout("document.getElementById('tips').style.opacity=1",0)	
}
function aboutFadeIn(){
	setTimeout("document.getElementById('about').style.opacity=1",0)	
}
	
function switchLayer(hideLayer,showLayer){

	var hide= document.getElementById(hideLayer)
	var show= document.getElementById(showLayer)
	
	toTop()	
	
	show.style.display = 'block'
	hide.style.display = 'none'
	
	hide.style.opacity = 0
	
	switch (showLayer) {
		case 'home':
			homeFadeIn()
		break
		case 'menu':
			menuFadeIn()
		break
		case 'tips':
			tipsFadeIn()
		break
		case 'about':
			aboutFadeIn()
		break
	}
}
