$(	function () {
	if ( $( '[rel="external"]' ).length > 0 ) {
		$( '[rel="external"]' ).each( function () {
			$( this ).attr( "target", "_blank" );
		} );
	}
} ); // al posto di externalLinks (deprecata)
$( function () {
	$( ".slideshow > li:first-child" ).fadeIn();
	ie67 = /MSIE 6.0|MSIE 7.0/.test( navigator.userAgent );
	if ( ( $( ".slideshow > li" ).length > 1 ) && ! ie67 ) {
		$( ".slideshow li" ).css( "position", "absolute" );
		setTimeout( "slideshow(0)", 1000 );
	}
} );
$( function () {
	$( "#mainMenu > li > ul" ).each( function () {
		$( this ).parent().mouseover( function () {
			$( "ul", this ).show();
		} );
		$( this ).parent().mouseout( function () {
			$( "ul", this ).hide();
		} );
	} );
	$( "#piede area" ).each( function () {
		$( this ).attr( "target", "_blank" );
	} );
} );
$( function () {
	attivaScrollPane();
	$( ".TestoBox > div, .FotoBox p" ).each( function () {
		if ( ! $( this ).hasClass( "selezionato" ) ) {
			$( this ).css( "opacity", 0 );
			$( this ).css( "visibility", "visible" );
		}
	} );
	if ( $( "[rel=lightbox]" ).length ) {
		$( "[rel=lightbox]" ).lightBox();
	}
} );
function slideshow( fotoCorrente ) {
	var numeroFoto = $( ".slideshow > li" ).length;
	if ( fotoCorrente == numeroFoto - 1 ) {
		var fotoSuccessiva = 0;
	} else {
		var fotoSuccessiva = fotoCorrente + 1;
	}
	if ( fotoSuccessiva != fotoCorrente ) {
		$( ".slideshow > li:eq(" + fotoCorrente + ")" ).fadeOut();
		$( ".slideshow > li:eq(" + fotoSuccessiva + ")" ).fadeIn();
		setTimeout( "slideshow(" + fotoSuccessiva + ")", 6000 );
	}
}
function deselezionaVociMenu( menuId ) {
	$( "#" + menuId + " > li" ).each( function () {
		$( this ).removeClass( "voceSelezionata" );
	} );
}
function selezionaVoceMenu( voceMenuId ) {
	$( "#" + voceMenuId ).addClass( "voceSelezionata" );
}
function contenutoSitoPrecedente( url, voceMenuId, indietroUrl ) {
	$( "#centro" ).fadeOut( function () {
		deselezionaVociMenu( "menuIstituzionale" );
		$( this ).html( '<img src="/images/loading.gif" alt="" />' );
		$( this ).fadeIn();
		$( this ).load( "/ajax/contenuto-sito-precedente.php?url=" + escape( url ) + "&voceMenuId=" + voceMenuId + "&indietroUrl=" + ( indietroUrl ? escape( indietroUrl ) : "" ), function () {
			deselezionaVociMenu( "menuIstituzionale" );
			selezionaVoceMenu( voceMenuId );
		} );
	} );
}
function testoStaticoAssociazione() {
	$( "#centro" ).fadeOut( function () {
		deselezionaVociMenu( "menuIstituzionale" );
		$( this ).html( '<img src="/images/loading.gif" alt="" />' );
		$( this ).fadeIn();
		$( this ).load( "/ajax/testo-statico-associazione.php", function () {
			deselezionaVociMenu( "menuIstituzionale" );
			selezionaVoceMenu( 'associazione' );
		} );
	} );
}
function immagineGalleria( immagine ) {
	$( "#content" ).fadeTo( 400, 0, function () {
		$( this ).load( "/ajax/immagine-galleria.php?immagine=" + immagine, function () {
			$( this ).fadeTo( 400, 1 );
		} );
	} );
}
function mostraTestoDaNonPerdere( identificatoreComune, index ) {
	var $menu = $( "#daNonPerdere" + identificatoreComune + " > ul > li" );
	var $contenuti = $( "#daNonPerdere" + identificatoreComune + " > .TestoBox > div" );
	var $foto = $( "#daNonPerdere" + identificatoreComune + " > .FotoBox > p" );
	for ( var i = 0; i < $menu.length; i++ ) {
		if ( i == index - 1 ) {
			$menu.eq( i ).addClass( "selezionato" );
			$contenuti.eq( i ).addClass( "selezionato" ).fadeTo( "normal", 1 );
			$foto.eq( i ).fadeTo(  "normal", 1 );
		} else {
			$menu.eq( i ).removeClass( "selezionato" );
			$contenuti.eq( i ).removeClass( "selezionato" ).fadeTo(  "normal", 0 );
			$foto.eq( i ).fadeTo(  "normal", 0 );
		}
	}
}
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 attivaScrollPane() {
	if ( $( ".scrollpane" ).length ) {
		$( ".scrollpane" ).jScrollPane();
	}
}
