// aprire pop-up
function apriPop(url, name, w, h) {
	var l = Math.floor((screen.width-w)/3);
	var t = Math.floor((screen.height-h)/3);
	window.open(url,name,"width=" + w + ",height=" + h + ",top=" + t + ",left=" + l);
}

// automazione per show/hide
function setSH() {

	var myElements = ".btSh";

	$(myElements).each(function(i) {

		$(this).click(function() {

			if($(this).next('div').css('display') == 'none')
				$(this).next('div').show('slow');
			else
				$(this).next('div').hide('slow');
		});
	});
}

// -------------------------------------------------------------------------

function blink(pId) {
	$('#'+pId).animate({opacity:'0.5'}, 500);
	$('#'+pId).animate({opacity:'1.0'}, 500);
}

// -------------------------------------------------------------------------
// SCROLL ORIZZONTALE

function setBtScrollH() {

	var interv = 500;

	var myScrLft = 0;

	$('#btScrollH_sx').click(function() {

		myScrLft = $('#riqScrollH_int').attr('scrollLeft')-interv;

		//alert('sx '+myScrLft);

		$('#riqScrollH_int').animate({ scrollLeft: myScrLft }, 2000);
	});

	$('#btScrollH_dx').click(function() {

		myScrLft = $('#riqScrollH_int').attr('scrollLeft')+interv;

		//alert('dx '+myScrLft);

		$('#riqScrollH_int').animate({ scrollLeft: myScrLft }, 2000);
	});
}

// -------------------------------------------------------------------------

function ordinaAlbero() {

	var myElements = ".ramo";

	$(myElements).each(function(i) {

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

		var arIds = $(this).attr('id').replace('ramo','').split('_');

		$(this).attr('id', arIds[0]).appendTo('#'+arIds[1]);

		$(this).css('display','block');
	});
}
// -------------------------------------------------------------------------

function setCittaFrmContatto(pProv) {
	$('.codComuneTmp').addClass('nascosto');
	$('#citta').addClass('nascosto');
	$('#codComune'+pProv).removeClass('nascosto');
	$('#nazione').attr('value','Italia');

	if(pProv == 'NOT ITALY' || pProv == '-1') {
		$('.codComuneTmp').addClass('nascosto');
		$('#citta').removeClass('nascosto');
		$('#nazione').attr('value','-1');
	}
}

function setProvFrmRicMercatino(pRegione) {
	$('.ric_prov').addClass('nascosto');
	$('#ric_prov_'+pRegione).removeClass('nascosto');
}

// -------------------------------------------------------------------------

function setFotoAnnuncio(pId) {
	$('.fotoAnnuncio').addClass('nascosto');
	$('#fotoAnnuncio'+pId).removeClass('nascosto');

	$('.thumbAnnuncio').addClass('imgThumb').removeClass('imgThumbActive');
	$('#thumbAnnuncio'+pId).removeClass('imgThumb').addClass('imgThumbActive');
}

// -------------------------------------------------------------------------

function setRecuperaPassword() {
	$('#tpLg').attr('value', 1);
	$('#rowPwd').remove();
	$('#txtRecPwd').removeClass('nascosto');
	$('#lnkRecPwd').addClass('nascosto');
	$('#btLogin').attr('value', 'INVIA PASSWORD');
}

// -------------------------------------------------------------------------

$(document).ready(function() {

	setSH();

	$("a.gallery").fancybox();

	setBtScrollH();

	ordinaAlbero();
});

