// 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_no() {

	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 setBtScrollH() {

	var interv = 150;

	var myScrLft = 0;

	var myElements = ".riqScrollH_int";

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

		var myId = $(this).attr('id');

		$(this).find('.btScrollH_sx').click(function() {

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

			$('#'+myId).animate({ scrollLeft: myScrLft }, 1000);
		});

		$(this).find('.btScrollH_dx').click(function() {

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

			$('#'+myId).animate({ scrollLeft: myScrLft }, 1000);
		});

	});


}

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

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 animateEmoz(pMov, pDelay) {

	//pMov = pMov*-1;

	setTimeout ( function(){

		$('#imgEmoz').animate({
			marginLeft: '+='+pMov,
			marginTop: '+='+pMov/3
		}, 7500, function() {
			pMov = pMov*-1;
			animateEmoz(pMov, 3000);
			});
	}, pDelay);

}

function animateEmozEllisse() {

	setTimeout ( function(){

		$('#imgEmoz').animate({
			path : new $.path.arc({
				center: [-100,-150],
				radius: 100,
				start: 0,
				end: -1,
				dir: 1
			}),
		},25000, function() {
			animateEmozEllisse();
		});

	}, 10);

}

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

$(document).ready(function() {

	setSH();

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

	setBtScrollH();

	ordinaAlbero();

	//animateEmoz(-400, 1000);
	animateEmozEllisse();

	//~ $('#element').mousedown(function(event) {
		//~ switch (event.which) {
			//~ case 1:
				//~ alert('Left mouse button pressed');
				//~ break;
			//~ case 2:
				//~ alert('Middle mouse button pressed');
				//~ break;
			//~ case 3:
				//~ alert('Right mouse button pressed');
				//~ break;
			//~ default:
				//~ alert('You have a strange mouse');
		//~ }
	//~ });

	$("img").rightClick( function(e) {
		alert(clickDxMsg);
	});

	$("#fancybox-content").rightClick( function(e) {
		alert(clickDxMsg);
	});

	$("#fancybox-outer").rightClick( function(e) {
		alert(clickDxMsg);
	});


});

