$(document).ready(function() {
	
	$('#friendlistlist').css("height","75px");
	$('#friendlistbutton').click(function() { 
		if (document.getElementById('friendlistlist').style.height != "75px") {
			$("#friendlistlist").animate({ height: "75px",}, 500 );
			document.getElementById('friendlistbutton').innerHTML = "&#8711; Draugu saraksts";
		} else {
			$("#friendlistlist").animate({ height: "100%"}, 500 );
			document.getElementById('friendlistbutton').innerHTML = "&#916; Draugu saraksts";
		}
		 return false
	});
	
	//Spēlu saraksta pārslēdzējs
	$('#pclist').click(function() {
		$('#pcgamelist').fadeIn("slow");
		$('#xboxgamelist').fadeOut("slow");
		$('#psgamelist').fadeOut("slow");
		$('#pclist').attr('class','openbutton');
		$('#xboxlist').attr('class','closebutton');
		$('#pslist').attr('class','closebutton');
		return false
	});
	$('#xboxlist').click(function() {
		$('#pcgamelist').fadeOut("slow");
		$('#xboxgamelist').fadeIn("slow");
		$('#psgamelist').fadeOut("slow");
		$('#pclist').attr('class','closebutton');
		$('#xboxlist').attr('class','openbutton');
		$('#pslist').attr('class','closebutton');
		return false
	});	
	$('#pslist').click(function() {
		$('#pcgamelist').fadeOut("slow");
		$('#xboxgamelist').fadeOut("slow");
		$('#psgamelist').fadeIn("slow");
		$('#pclist').attr('class','closebutton');
		$('#xboxlist').attr('class','closebutton');
		$('#pslist').attr('class','openbutton');
		return false
	});	
	
	//Profila izeja
	$('#profilexit').hover(function() {
		$('#profilimg').addClass('transparency');
	},
		function() {
		$('#profilimg').removeClass('transparency');
	});

	//Fancy Box iekš spēļu saraksta
	$("a.fancyrame").click(function() {
        $.fancybox({
         'padding'             : 0,
         'autoScale'   		   : false,
         'transitionIn'        : 'none',
         'transitionOut'       : 'none',
         'title'               : this.title,
         'width'               : 710,
         'height'              : 425,
         'href'                : this.href.replace(new RegExp("watch\\?v=", "i"), 'v/') + '&autoplay=1',
         'type'                : 'swf',    // <--add a comma here
         'swf'				   : {'allowfullscreen':'true', 'wmode':'transparent'}
         });
        return false;
   });
   
   $(".star").mouseover(function() {
   		var subclass = this.className.split(/\s+/);
   		var star = subclass[1].substr(5,1);
		var starid = subclass[1].substr(6);
		while (star != 0) {
			$(".stars"+star+starid).css("background-position","center bottom");
			--star;
		}

   }).mouseout(function() {
   		var subclass = this.className.split(/\s+/);
   		var star = subclass[1].substr(5,1);
		var starid = subclass[1].substr(6);
		while (star != 0) {
			$(".stars"+star+starid).css("background-position","center top");
			--star;
		}
		star = 5;
		while (star != 0) {
			subclass = $("a.stars"+star+starid).attr('class');
				if (subclass.search("starrate") == -1) {
					$(".stars"+star+starid).css("background-position","center center");
				}
			--star;
		}

   });

});
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') {
				popmessage(json.rz);
			}
			else if (json.rx == '021') {
				$("#votecounteiner").html(json.ry);
			}
			else if (json.rx == '030') {
				$("#loderconteiner"+json.rz).html(json.ry).slideToggle('slow');
			} 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) }

function popmessage(text) {
	$('#popupmessage').html(text);
  	$('#popupmessage').slideDown('slow', function() {
   		var t=setTimeout("popmessageDown()",6000);
  	});
}

function popmessageDown() {
	$('#popupmessage').slideUp('slow');	
}

var tvt = setTimeout("tvboxloop()",8000);
var tick = 2;

function settvbox(args){
	tick = args;
	clearTimeout(tvt);
	tvboxloop();
}

function tvboxloop() {
		for (i=1;i<=5;i++) {
			 if ($(".bigimg"+i).css("display") != "none") {
			 	$(".bigimg"+i).css("display","none");
			 }
			 if ($(".tvtext"+i).css("display") != "none") {
			 	$(".tvtext"+i).css("display","none");
			 }		
			 if ($(".tvclick"+i).css("border") != "#bcbcbc") {
			 	$(".tvclick"+i).css("border","1px solid #bcbcbc");
			 }	 
		}
		
		$(".bigimg"+tick).fadeIn("slow");
		$(".tvtext"+tick).fadeIn("slow");
		$(".tvclick"+tick).css("border","1px solid #fbb311");
		++tick;
	if (tick >= 6) {
		tick = 1;
	}
   	tvt = setTimeout("tvboxloop()",8000);
}

