/**
 *	JQuery per i filtri delle pagine
 *	06/12/2007 16.38.19
 */

filtri0ris = "Troverai 0 strutture: prova a cambiare i tuoi filtri.";
filtri1ris = "Troverai 1 struttura: per vederla premi il tasto Filtra ->";
filtriXris1 = "Troverai ";
filtriXris2 = " strutture: per vederle premi il tasto Filtra ->";

function loadListingImgs(){
	
	
	jQuery.each($("img.icona"), function() {		//alert( $(this).attr("name") );
		if ( $(this).attr("name") != undefined ){
			$(this).attr("src", "http://www.agriturismo.it" + $(this).attr("name") + "azienda.jpg" );
		}
	});
}
function loadFiltriData(){
	
	
	$.getJSON("/tools/filtri.jsp?" + $('form#filtri').serialize(), function(json){
		for (var i = 0; i < json.length; i++) {	//$("#filtri label[for='" + json[i].filtro +"'] span.count").text("(" + json[i].count + ")");	
			$("input[name='" + json[i].filtro + "']").parent().children("span").text("(" + json[i].count + ")");		
			
			// se 0 disabilito il filtro	alert( json[i].filtro + ": " + $("input[name='" + json[i].filtro + "']").attr("checked") );
			if (
				( json[i].count == 0 ) &&
				( $("input[name='" + json[i].filtro + "']").attr("checked") == undefined ) &&
				( $("input[name='" + json[i].filtro + "']").attr("type") != "radio" ) 
			){
				$("input[name='" + json[i].filtro + "']").attr("disabled","disabled");
			} else {
				$("input[name='" + json[i].filtro + "']").removeAttr("disabled");					
			}
/*
			if (json[i].filtro == "posizione"){
				posizione = json[i].count ;
			} else 
			if (json[i].filtro == "posmare"){
				posmare = json[i].count ;
			} else 
			if (json[i].filtro == "poslago"){
				poslago = json[i].count ;
			} else 
			if (json[i].filtro == "posmont"){
				posmont = json[i].count ;
			} 
*/
		}
		
/*
		if ( posizione > 1){
			if (posmare == 0){
				$("label[@for='posmare']").hide();
			}
			if (poslago == 0){
				$("label[@for='poslago']").hide();
			}
			if (posmont == 0){
				$("label[@for='posmont']").hide();
			}
			$("#tr-posizione").show();	
		}
*/
	});
	
}


$(document).ready(function () {

	// sposta i filtri dalla colonna di destra a quella di sinistra
	//
	$("ul.listing:eq(0)").prepend($("div.boxFiltri"));
	//alert($("td.maincol").width() + " " + $("td.sidebar").width() + " : " + ($("td.maincol").width() + $("td.sidebar").width() ) );
	//window.status = ($("td.maincol").width() + " " + $("td.sidebar").width() + " : " + ($("td.maincol").width() + $("td.sidebar").width() ) );
	//	carico le immagini del listing
	setTimeout('loadListingImgs()', 800);
	
	loadFiltriData();
//	-caricamento pagina listing


	$(".filtri-avanzati-controller a.show").click(function (e) {
		$(".filtro-avanzato").show();
		$(this).hide();
		$(".filtri-avanzati-controller a.hide").css("display", "inline");
		return false;
	});
	
	$(".filtri-avanzati-controller a.hide").click(function (e) {
		$(".filtro-avanzato").hide();
		$(this).hide();
		$(".filtri-avanzati-controller a.show").css("display", "inline");
		return false;
	});
	
	//	i filtri sui checkbox
	$("#filtri input[name!='filtra']").click(function (e) {
		loadFiltriData();
		$("#filtra").addClass("on");
	});
	
	$("#filtri select").change(function (e) {
		loadFiltriData();
	});
	
	
	
	$("#filtra").mouseover( function() { 
		$("#filtra").addClass("hover");
	});
	$("#filtra").mouseout( function() { 
		$("#filtra").removeClass("hover");
	});
	
	$("#filtri label").mouseover( function() { 
		$(this).addClass("hover");
	});
	$("#filtri label").mouseout( function() { 
		$(this).removeClass("hover");
	});
	
	/*
//	mostra la mappa della struttura	
	$(".agriIndirizzo a").mouseover( function() { 
		agri = $(this).parent().parent().attr("id");//		alert( agri );
		$( "#" + agri + " .agriMap" ).html("<img src=\"http://www.agriturismo.it/" + agri + "/map1.jpg\" width=\"400\" height=\"400\" alt=\"" + agri + "\">").fadeIn(200);
	});
	$(".agriIndirizzo a").mouseout( function() { 
		agri = $(this).parent().parent().attr("id");//		alert( agri );
		$( "#" + agri + " .agriMap" ).fadeOut(200);
	});
//	-mappa struttura
	*/
	
//	mostra i filtri già selezionati
	$(".filtro-text a").click( function() { 
		filtro = $(this).parent().parent();
		filtro.children(".filtro-text").hide();
		filtro.children(".filtro-input").show();
		return false;
	});
//	
	
	
});

	/*
	
var jsonReg;
	if ( id_regione != undefined ){
	//	caricamento pagina listing
		$.getJSON("/tools/regione_prov.jsp?idRegione=" + id_regione, function(json){
			jsonReg = json;
		});
	}

	if ( id_regione != undefined ){
		$("#map-regione area").mouseover( function() { 
			prov = $(this).attr("id");
			provincia = $(this).attr("alt");//		alert( prov );
			strutture = eval( "(" + jsonReg[prov] + ")" );
			if (!strutture){
				strutture = 0;	
			}
			$(".sidebar-dida").fadeIn(300).text(provincia + " - numero strutture: " +  strutture);
		});
		$("#map-regione area").mouseout( function() { 
			$(".sidebar-dida").text("");
		});
	}*/

