//definizione variabili globali
var fs_counter=0;
var fs_max=0;
var fs_width=0;
var fs_height=0;


function updateNewsCounter(nid)
{
	$.post("../functions/json.php?w=updcounter", {nid : nid}, function(data){if(data.res==1) return true; else return false;},"json");	
}

function check_antispam(code, user)
{
	$.post("functions/json.php?w=antispam", { as : user, idas : code }, function(data)

												   {
												   	if(data.as==1)
    													return true;
    												else
    													return false;
    											   }
   			,"json");

}

function insertComment(code, user, name, email, text, news)
{
	$("#comment_l").append(' - <font color="red">sto caricando...</font>');
	$("#submit").hide();
	$("#loading").show("slow");
    $.ajax({
        type: 		"post",
		url: 		"../functions/json.php?w=i_comment",
		data: 		"as="+user+"&idas="+code+"&p="+name+"&e="+email+"&n="+news+"&c="+text,
		dataType:	"json",
		success:	function(data){if(data.ok==1){$("#send_comment").slideUp("normal");$("#r_title").text(data.poster);$("#r_body").text(data.comment);$("#reserv").slideDown("normal");} else alert("codice antispam non corretto. riprova");},
        error:      function(){alert('impossibie salvare il commento');}
		});	
}

function delete_comment(id)
{
	$.post("functions/json.php?w=d_comment", {id_c : id}, function(data)
															{
																if(data.ok==1)
																{
																	$("#"+id).slideUp("slow");
																	//alert("ok");	
																}
																else
																	alert(data.detail);
															}, "json");
}

function gv(id)
{
	//alert($("#"+id).val());
	return $("#"+id).val();
}

//oggetto foto settimana
function fotoSettimana(nome,thumb,foto)
{
	this.nome=nome;
	this.thumb=new Image();
	this.thumb.src=thumb;
	this.foto=foto;
}

//carica foto settimana
function loadFS(n)
{
	$.post("functions/json.php?w=loadFS", {n:n}, 
												function(data)
												{
													fs_width=data.width;
													fs_height=data.height;
													$.each(data.pic,function(i,p){a.push(new fotoSettimana(p.nome,p.thumb,p.foto));});
												}
   			, "json");	
}

function initFSslideShow(n,s)
{
	fs_counter=s;
	fs_max=n;
}

//cambia foto settimana
function changeFS(direction)
{
	//prossima img da mostrare
	fs_counter=(fs_counter+direction)%fs_max;
	
	if(fs_counter<0)
		fs_counter=fs_max-1;
	
	//nasconde momentaneamente il div
	$("#fs").fadeOut("slow",
					 function() 
					 {
						//setta titolo immagine
						$("#fs_title").text(a[fs_counter].nome);
						//setta titolo immagine
						$("#fs_title").text(a[fs_counter].nome);
						//cambia immagine e dimensioni div
						$("#fs_container").css({"backgroundImage":"url("+a[fs_counter].thumb.src+")","width":a[fs_counter].thumb.width+"px","height":a[fs_counter].thumb.height+"px"});
						//cambia link immagine
						$("#ifs a").attr("href",a[fs_counter].foto);
						//visualizza il div modificato
						$("#fs").fadeIn("slow");						
					 });
}

