$(document).ready(function() {
	$('#monitor1').load('http://uoc.lv/addons/psychoquery1/query.php');
	$('#monitor2').load('http://uoc.lv/addons/psychoquery2/query.php');
	$('#stars1').click(function() {starreset(); document.getElementById('stars1').style.backgroundPosition = "center center"; });
	$('#stars2').click(function() {starreset(); document.getElementById('stars2').style.backgroundPosition = "center center"; });
	$('#stars3').click(function() {starreset(); document.getElementById('stars3').style.backgroundPosition = "center center"; });
	$('#stars4').click(function() {starreset(); document.getElementById('stars4').style.backgroundPosition = "center center"; });
	$('#stars5').click(function() {starreset(); document.getElementById('stars5').style.backgroundPosition = "center center"; });
	$('#stars6').click(function() {starreset(); document.getElementById('stars6').style.backgroundPosition = "center center"; });
	$('#stars7').click(function() {starreset(); document.getElementById('stars7').style.backgroundPosition = "center center"; });
	$('#stars8').click(function() {starreset(); document.getElementById('stars8').style.backgroundPosition = "center center"; });
	$('#stars9').click(function() {starreset(); document.getElementById('stars9').style.backgroundPosition = "center center"; });
	$('#stars10').click(function() {starreset(); document.getElementById('stars10').style.backgroundPosition = "center center"; });
});

function starreset() {
	document.getElementById('stars1').style.backgroundPosition = "top center";
	document.getElementById('stars2').style.backgroundPosition = "top center";
	document.getElementById('stars3').style.backgroundPosition = "top center";
	document.getElementById('stars4').style.backgroundPosition = "top center";
	document.getElementById('stars5').style.backgroundPosition = "top center";
	document.getElementById('stars6').style.backgroundPosition = "top center";
	document.getElementById('stars7').style.backgroundPosition = "top center";
	document.getElementById('stars8').style.backgroundPosition = "top center";
	document.getElementById('stars9').style.backgroundPosition = "top center";
	document.getElementById('stars10').style.backgroundPosition = "top center";
}

function DraugiemSay( title, url, titlePrefix ){
 window.open(
  'http://www.draugiem.lv/say/ext/add.php?title=' + encodeURIComponent( title ) +
  '&link=' + encodeURIComponent( url ) +
  ( titlePrefix ? '&titlePrefix=' + encodeURIComponent( titlePrefix ) : '' ),
  '',
  'location=1,status=1,scrollbars=0,resizable=0,width=530,height=400'
 );
 return false;
}

function send(datax,datay,dataz) {
	$.getJSON('http://uoc.lv/jCore.php', { px: datax,py: datay,pz: dataz}, function(json){
		if(json.rx!=null) {
			if (json.rx == '000') { alert('Pieejams, tikai reģistrētiem lietotājiem.'); }
			else if (json.rx == '001') { alert('Ups.. Notikusi kļūme. --> '+ json.rx +' --> '+ json.ry +' --> ' + json.rz); }
			else if (json.rx == '005') { alert(json.ry); }
			else if (json.rx == '010') {
				document.getElementById('counter_'+json.ry).innerHTML--;
				if (document.getElementById('counter_'+json.ry).innerHTML > 0) { document.getElementById('counter_'+json.ry).setAttribute("class", "repplus");}
				else if (document.getElementById('counter_'+json.ry).innerHTML < 0) { document.getElementById('counter_'+json.ry).setAttribute("class", "repred");}
				else { document.getElementById('counter_'+json.ry).setAttribute("class", "repnet") }	
			}
			else if (json.rx == '011') { 
				document.getElementById('counter_'+json.ry).innerHTML++;
				if (document.getElementById('counter_'+json.ry).innerHTML > 0) { document.getElementById('counter_'+json.ry).setAttribute("class", "repplus");}
				else if (document.getElementById('counter_'+json.ry).innerHTML < 0) { document.getElementById('counter_'+json.ry).setAttribute("class", "repred");}
				else { document.getElementById('counter_'+json.ry).setAttribute("class", "repnet") }
			}
			else if (json.rx == '020') {
					document.getElementById('score').innerHTML = json.ry;	
			} else { alert('Ups.. Notikusi kļūme. --> '+ json.rx +' --> '+ json.ry +' --> ' + json.rz); }
		} else { alert('Ups.. Notikusi kļūme.'); } 
	});
}

function isEmpty( inputStr ) { return !(inputStr&&inputStr.length) }