// JavaScript Document<script>

var time_random_game = 2000;

var cordinate_swf;

var swf_show = false;

var patch = "http://www.giochiflashgratis.it/";

var patch_no_loging = "http://www.giochiflashgratis.it/multiplayer/effettua_loging.php";



 

 

function categoryLed(){



var n = $(".simplebox.category li").size();



var randomnumber=Math.floor(Math.random()*n);



$(".simplebox.category li").eq(randomnumber).children("a").children("img").animate({opacity:0.5},"slow");

setTimeout("$('.simplebox.category li').eq("+randomnumber+").children('a').children('img').animate({opacity:1},'fast');",1000);

setTimeout("categoryLed()",1000);

											  

											  

											  };

$(document).ready(



function(){
	

	
$("#chat-body").animate({scrollTop:0},"fast");

var value_nickname = $("#header .nickname").val();

$("#header .nickname").blur(function(){

											

											 if($(this).val()==""){

												 $(this).val(value_nickname);

												 };

											 

											 }						

									

									).focus(function(){

									

											 if($(this).val()==value_nickname){

												 $(this).val("");

												 }

											 

											 }												

										);

										

var value_password = $("#header .password").val();

$("#header .password").blur(function(){

											

											 if($(this).val()==""){

												 $(this).val(value_password);

												 };

											 

											 }						

									

									).focus(function(){

									

											 if($(this).val()==value_password){

												 $(this).val("");

												 }

											 

											 }												

										);	

var value_search = $("#search .text").val();

$("#search .text").blur(function(){

											

											 if($(this).val()==""){

												 $(this).val(value_search);

												 };

											 

											 }						

									

									).focus(function(){

									

											 if($(this).val()==value_search){

												 $(this).val("");

												 }

											 

											 }												

										);	



var value_chat = "Scrivi un messaggio";

$("#add-msg-chat .text").val(value_chat);

$("#add-msg-chat .text").blur(function(){

											

											 if($(this).val()==""){

												 $(this).val(value_chat);

												 };

											 

											 }						

									

									).focus(function(){

									

											 if($(this).val()==value_chat){

												 $(this).val("");

												 }

											 

											 }												

										);	





// Immagine giochi

$(".game .image").mousemove(function(){

									 

									 $(this).children(".overlay").show();

									 

									 

									 }

							

							).mouseout(function(){

								

								      

									 $(this).children(".overlay").hide();

								

								

								

								

								      });

$(".games-category ul li").mousemove(function(e){

									

									$(this).children(".image").show();		

									$(this).children(".image").css("left",(e.pageX+20)+"px").css("top",e.pageY+"px");												

											

											

											

											

									}).mouseout(function(){

												

									$(this).children(".image").hide();			

												

												

									});



refresh_chat();



// Scroll chat


	var chat_value_scroll = 100;

	var chat_current_scroll = 0;

	

	var content_chat = document.getElementById("chat-body");




    $("#chat .top").css("display","none");

	$("#chat .top").click(function(){

									   

			chat_current_scroll -= chat_value_scroll;

			$("#chat-body").animate({scrollTop:chat_current_scroll},"fast");

		    

			if(chat_current_scroll <= 0 ){

			

			$(this).css("display","none");

			

			}

									

					$("#chat .bottom").css("display","block");

						  

									  });		

	

		$("#chat .bottom").click(function(){

		//	content.scrollTop+=10;

			chat_current_scroll += chat_value_scroll;





			$("#chat-body").animate({scrollTop:chat_current_scroll},"fast");

		

		

			

			$("#chat .top").css("display","block");

			

			if(chat_current_scroll+188 >= content_chat.scrollHeight){

				

			$(this).css("display","none");

				

				}



	

							   

									   });

		

	

	// Giochi random in sidebar

		

		setTimeout("randomGame('#random-games');",time_random_game );





	/*

$("#navigation-content li").each(

	function(i){

	if($(this).hasClass('select')){

	$(i).html;

	}

	}

);*/



elements = $("#navigation-content #category li");

for(i=0;i<elements.length;i++){

	

	if($(elements[i]).hasClass('select')){

	

		precedente = i-1;

		successivo = i+1;

		



			$(elements[precedente]).css("background","url('style/image/cat-sp2.png') right bottom no-repeat");

		

	

	

	}





}



$("#navigation-content #category .other a").click(

function(){



$("#navigation-content #category li").each(function(i){

		time = i*1000;

		

		$(this).hide(time);



});

time-=3000;

setTimeout("$('#navigation-content #category').css('display','none');",time);

setTimeout("$('#navigation-content #other-category').css('display','block');",time);



$("#navigation-content #other-category li").each(function(i){

time += i*50;

	$(this).show(time);



});

}

);$("#navigation-content #other-category .other a").click(

function(){

$("#navigation-content #other-category li").each(function(i){

time = i*1000;

	$(this).hide(time);



});

time-=3000;

setTimeout("$('#navigation-content #category').css('display','block');",time-1000);



setTimeout("$('#navigation-content #other-category').css('display','none');",time-1000);





$("#navigation-content #category li").each(function(i){

		time += i*50;

		

		$(this).show(time);



});





}

);

		/* Segnala amico */

$("#form-invia-sfida").submit(function(){

									  var option = {

											success:function(result){

										

												if(result=="404"){

													$("#segnala-amico .msg").html("<span style='color:red'><img src='"+patch+"template/style/image/alert.gif'/> Controlla i campi , si è verificato un errore</span>"); 

													}else{

															$("#segnala-amico .msg").html("<span style='color:green'><img src='"+patch+"template/style/image/ok.png'/> Sfida inviata con successo</span>"); 

														$("#form-invia-sfida").clearForm();

													}

											}

										}

										

									$(this).ajaxSubmit(option);

									  

									   return false;

									   });

		$("#add-msg-chat").submit(function(){

										msg =   $("#add-msg-chat [name ='msg']").val(); 
										if(msg == value_chat || $.trim(msg) == 0){
											return false;
											}	
										var option = {

											success:function(result){

												 if(result == "error_loging"){

													 location.href = patch_no_loging;

													 }else{

													$(this).attr("disabled","disabled");

													 $("#add-msg-chat  .submit").attr("disabled","disabled");

													 for(var i=5;i!=0;i--){

													 setTimeout('$("#add-msg-chat [name =\'msg\']").val("Aspetta : '+i+'");',(5-i)*1000);

														 }

													 setTimeout('$("#add-msg-chat[name =\'msg\']").attr("disabled","");$("#add-msg-chat [name =\'msg\']").val("");$("#add-msg-chat .submit").attr("disabled","");',5000);

													 

													 $("#chat .body").prepend(result);

													 $("#chat-body").animate({scrollTop:0},"fast");

													 $("#add-msg-chat [name ='msg']").val("");

													 chat_current_scroll = 0;

													 $("#chat .top").css("display","none");

													 }

											}

										}

										

										if(trim(msg)!=""){

											

											

										$(this).ajaxSubmit(option);

										

										

										}

										

										return false;

										

										});

		

			

		

		

		}





		

);

function refresh_chat(){

	var min_tempo = 5000; // secondi

	
$.ajax({
	   url: patch+"modules/minichat.php",
	   cache: false,
	   type: "GET",
	   data: {op:"refresh"},
	   success: function(result){

						

			$("#chat .body").html(result);			 

						 

						 }
	   });


	

	setTimeout("refresh_chat()",min_tempo);

	

}

	

	function refresh_classifica(game){

	$.ajax({
	url: patch+"modules/game.php",
	   cache: false,
	   type: "GET",
	   data: {op:"classifica_game",n:2,pr1:game,pr2:5},
	   success: function(result){

																				  

$("#classifica ul").html(result);			 

						 

						 }
	   
		   });



	

	

}

	function randomGame(id){

		elements = $(id+" li img");

						

			for(i=0;i<elements.length;i++){

		

			$(elements[elements.length-(i+1)]).animate({opacity:0.0}, 1000*(i+1));

		



		//	$(elements[elements.length-(i+1)]).hide( 1000*(i+1));

		

		

			}

			

			setTimeout("call_random_games('"+id+"')",1000*i);

			

			setTimeout("animate_game_list('"+id+"')",(1000*i)+500);									

																

			

			

		}

	function call_random_games(id){

	$.ajax({
	
	url: patch+"modules/game.php",
	   cache: false,
	   type: "GET",
	   data: {op:"random_games",limit:9},
		seccuess:function(result){

						

						$(id).html(result);

						$(id+" li img").css("opacity",0.0);

						

		}   
		   });

	}

	function animate_game_list(id){



		elements = $(id+" li img");

		

		for(i=0;i<elements.length;i++){

	

			$(elements[i]).animate({opacity:1}, 1000*i);

		



			

		

			}	

			

			setTimeout("randomGame('#random-games');",time_random_game*2 );

			

		}

		

		

	

		

		function findElementPosition(obj) {

        var cordinate= {x:0,y:0};

        if (obj.offsetParent) {

          cordinate.x = obj.offsetLeft

          cordinate.y = obj.offsetTop

          while (obj = obj.offsetParent) {

           cordinate.x += obj.offsetLeft

           cordinate.y += obj.offsetTop

          }

        }

      

        return cordinate;

}

function cordinate_assolute(idObj) {

    var obj, coords;

    obj=document.getElementById(idObj);

    coords = findElementPosition(obj);

    return coords;

}

			function fullmode() {

				

			

cordinate_swf = cordinate_assolute("swf");





				



	x = "-"+cordinate_swf.x+"px";

	y = "-"+(cordinate_swf.y-20)+"px";

	

$("#swf_full").css("visibility","visible").animate({opacity:1},"fast");

	var A;

	if(self.innerWidth!=undefined)A= [self.innerWidth,self.innerHeight];

	else{

	var D= document.documentElement;

	if(D) A= [D.clientWidth,D.clientHeight];

	}





$('#swf').css("position","absolute");



$("#swf_full_exit").css("left",A[0]-80+"px");

$("#swf_full_exit").css("top",((A[1])-50)+"px");



$("#swf_full_exit").css("visibility","visible");



cordinate_stars = cordinate_assolute("stars");



cordinate_stars.y = parseInt("-"+cordinate_stars.y);

/*

$(".page-game #game #stars").css("left","20px");

$(".page-game #game #stars").css("top",((cordinate_stars.y+A[1])+540)+"px");

*/





	$('#swf').animate({left:x,top:y,width:A[0]+"px",height:A[1]-60+"px"},1000);

		swf_show= true;

	

	

//	$('#swf').animate({left:x,top:y},1000).css("width",A[0]-60+"px").css("height",A[1]-50+"px");

		swf_show= true;



	

	/* Per ie */

		$('html, body').scroll(function(){

				if(swf_show==true){									

		$('html, body').animate({scrollTop:0}, 'fast');

									

				}

									}

								);	

		/* Per firefox */

		$(document).scroll(function(){

				if(swf_show==true){						

		$('html, body').animate({scrollTop:0}, 'fast');

				}

							

									}

								);

	$('html, body').animate({scrollTop:0}, 'fast');
	
	

	

	

	

}

function close_fullmode(){



swf_show = false;



	

	$('#swf').animate({left:"30px",top:"23px"},1000).css("width","568px").css("height","524px");

	

$("#swf_full_exit").css("visibility","hidden");

	$("#swf_full").css("visibility","hidden").animate({opacity:0},"fast");

	/*

$(".page-game #game #stars").css("left","0px");

$(".page-game #game #stars").css("top","592px");

*/

$(document).scroll(function(){

										

		

									

							

									}

								);

	}

function rating(g,v){

	

	$.get(patch+"modules/game.php",{op:"rating",gioco:g,voto:v},function(result){

		

			if(v==1){

				

	//	$('.page-game #game #stars .no').addClass("none");

//		$('.page-game #game #stars .si').removeClass("none");
		$('.page-game #game #stars .no a').css("display","none");
		$('.page-game #game #stars .no').animate({opacity:0,width:"0px"},1000);

		

		}else{

	//	$('.page-game #game #stars .si').addClass("none");

	//	$('.page-game #game #stars .no').removeClass("none");

		$('.page-game #game #stars .si').animate({opacity:0,width:"0px"},1000);

		}		

	

			

				

			

																   })



			

	}	

	function copy_code(id){

	

		element = $(id);

		element.select();

		document.execCommand('Copy');

		

		}

	

	function add_in_preferiti(){

		

		var bookmarkurl = "http://www.giochiflashgratis.it";

		var bookmarktitle = "Giochi gratis"; 

 	

	

		if (document.all){

		window.external.AddFavorite(bookmarkurl,bookmarktitle);

		}

		

		if (window.sidebar) { // firefox

		window.sidebar.addPanel(bookmarktitle, bookmarkurl, "");

		}

	}	

	 

function trim(str, chars) {

	return ltrim(rtrim(str, chars), chars);

}

 

function ltrim(str, chars) {

	chars = chars || "\\s";

	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");

}

 

function rtrim(str, chars) {

	chars = chars || "\\s";

	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");

}

function changeAvatar(patch_avatar,classAvatar,id){

	

	$(".avatar_current").attr("src",patch_avatar);

	$("#avatar-list .evident").removeClass();

	$("#"+classAvatar).addClass("evident");

	

	$.get(patch+"modules/users.php",{op:"change_avatar",avatar:id},function(result){

						

						 });

	}





