$(	function () {
	if ( $( '[rel="external"]' ).length > 0 ) {
		$( '[rel="external"]' ).each( function () {
			$( this ).attr( "target", "_blank" );
		} );
	}
} ); // al posto di externalLinks (deprecata)
$( function() {
	$( "#nav li" ).each( function () {
		this.onmouseover = function() {
			$( this ).addClass( "sfhover" );
		};
		this.onmouseout = function() {
			$( this ).removeClass( "sfhover" );
		};
	} );
} );
function spedisci( email ) {
	location = "mailto:" + email.replace( "[presso]", "@" );
}
function preferiti() {
	url = window.location.toString();
	titolo = document.title;
	if ( window.sidebar ) {
		window.sidebar.addPanel( titolo, url, "" );
	} else if ( window.external ) {
		window.external.AddFavorite( url, titolo );
	}
}
function stampaPagina() {
	window.print();
}
function mostraTesto( voceDaEvidenziare ) {
	for ( var i = 0; i < elencoTesti.length; i++ ) {
		if ( elencoTesti[i] != voceDaEvidenziare && $( "#testo" + elencoTesti[i] ).css( "display" ) == "block" ) {
			var voceDaNonEvidenziare = elencoTesti[i];
			$( "#testo" + voceDaNonEvidenziare ).fadeOut( function () {
				$( "#testo" + voceDaEvidenziare ).fadeIn();
				if ( $( "#foto" + voceDaNonEvidenziare ).length ) {
					$( "#foto" + voceDaNonEvidenziare ).fadeOut( function () {
						$( "#foto" + voceDaEvidenziare ).fadeIn();
					} );
				} else {
					$( "#foto" + voceDaEvidenziare ).fadeIn();
				}
				$( "#voceMenu" + voceDaNonEvidenziare ).css( "font-weight", "normal" );
				$( "#voceMenu" + voceDaEvidenziare ).css( "font-weight", "bold" );
			} );
		}
	} 
}
function convalidaRichiestaInformazioni() {
	return true;
}
function credits() {
	var div = $( "#credits" );
	if ( div.css( "display" ) == "block" ) {
		div.fadeOut();
	} else {
		div.fadeIn( function () {
			$( window ).one( "click", function () {
				credits();
			} );
		});
	}
}
function inviaPagina( form ) {
	errori = "";
	if ( form.nomeMittente.value == "" ) {
		errori += "Il campo Mittente è obbligatorio\n";
	}
	if ( ! validateEmail( form.emailMittente.value ) ) {
		errori += "L'indirizzo email del mittente non è valido\n";
	}
	if ( form.nomeDestinatario.value == "" ) {
		errori += "Il campo Destinatario è obbligatorio\n";
	}
	if ( ! validateEmail( form.emailDestinatario.value ) ) {
		errori += "L'indirizzo email del destinatario non è valido\n";
	}
	if ( errori ) {
		alert( errori );
	} else {
		$.post( form.action, $( form ).serialize(), function ( data ) {
			eval( data );
		} );
	}
	return false;
}
function validateEmail( email ) {
	var emailReg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/;
	var emailReg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,6}|[0-9]{1,3})(\]?)$/;
	return ! emailReg1.test( email ) && emailReg2.test( email );
}
function apriChiudiInviaPaginaDiv() {
	if ( $( "#inviaPaginaDiv" ).css( "display" ) == "block" ) {
		$( "#inviaPaginaDiv" ).slideUp();
	}  else {
		$( "#inviaPaginaDiv" ).slideDown();
	}
}
function inverno() {
	win = window.open( "inverno.php", "inverno", "width=800,height=550" );
	win.focus();
}
function lightboxGallery() {
	$( "[rel=lightboxGallery]" ).lightBox(
		{fixedNavigation: true,
		imageLoading: "/images/lightbox/loading.gif",
		imageBlank: "/images/lightbox/blank.gif",
		imageBtnClose: "/images/lightbox/close.gif",
		imageBtnPrev: "/images/lightbox/prev.gif",
		imageBtnNext: "/images/lightbox/next.gif",
		containerResizeSpeed: 350,
		txtImage: "Immagine",
		txtOf: "di" } );
}
$( function () {
	lightboxGallery();
} );
