// ----------------------------------------------------------------------------- 
// Lettura immagine grande Galleria 
// Ci si aspetta di avere il vettore 'zoom_array[]'
// ----------------------------------------------------------------------------- 

	$(document).ready( 
		function() {
			
			var totImages = zoom_array.length;
			var p = 0;
			
			// --------------------------------------------------------
			// Immagine di default 
			// --------------------------------------------------------
			$('#imageContainerMax').append('<DIV CLASS="loadingImg">loading image...</DIV>');
			
			var imgThumb = new Image();
			$(imgThumb).attr('src', zoom_array[p]).load(
				function () {
					$('#imageContainerMax').empty();
					$(this).hide();
					//$('#contentArea').prepend('<DIV ID="navigArea"><A HREF="#" ID="prevImg" CLASS="galleryBut">Indietro</A> <a href="#" ID="galleryClose" CLASS="galleryBut">Chiudi</a> <A HREF="#" ID="nextImg" CLASS="galleryBut">Avanti</A></DIV>');
					$('#imageContainerMax').append(this);
					$(this).fadeIn( "slow", 
						function () {
							
							// --------------------------------------------------------
							// --- Tasto NEXT ---
							// --------------------------------------------------------
							$("a#nextImg").click( 
								function() {
									if ( p < (totImages-1) ) {
										p = p + 1;
									} else {
										p = 0;
									}
									
									$(imgThumb).fadeOut( "slow", 
										function () {
											$('#imageContainerMax').empty().append('<DIV CLASS="loadingImg">loading image...</DIV>');
											
											var imgThumb = new Image();
											$(imgThumb).attr( 'src', zoom_array[p] ).load(
												function () {
													$('#imageContainerMax').empty();
													$(this).hide();
													
													$('#imageContainerMax').append(this);
													$(this).fadeIn();
														
												})
												.error(function () {
													// notify the user that the image could not be loaded
													alert( 'Immagine mancante...' + zoom_array[p] );
												})
										});
									return false;
								});
								// End {"click"} Next
							// --------------------------------------------------------
							
							
							// --------------------------------------------------------
							// --- Tasto PREV ---
							// --------------------------------------------------------
							$("a#prevImg").click( 
								function() {
									if ( p > 0 ) {
										p = p - 1;
									} else {
										p = (totImages-1);
									}
									
									$(imgThumb).fadeOut( "slow", 
										function () {
											$('#imageContainerMax').empty().append('<DIV CLASS="loadingImg">loading image...</DIV>');
											
											var imgThumb = new Image();
											$(imgThumb).attr( 'src', zoom_array[p] ).load(
												function () {
													$('#imageContainerMax').empty();
													$(this).hide();
													$('#imageContainerMax').append(this);
													$(this).fadeIn();													
												})
												.error(function () {
													// notify the user that the image could not be loaded
													alert( 'Immagine mancante...' + zoom_array[p] );
												})
										});
									return false;
								});
								// End {"click"} Prev
							// --------------------------------------------------------
																																			
		
						});
						// End {"fadeIn"} 
						
						
						// --------------------------------------------------------
						// Accendo le categorie 
						// --------------------------------------------------------
						//$('#toolCollectionList').slideDown();
						//p = 'on';
						// --------------------------------------------------------
						
						
				})
				.error( function () {
					// notify the user that the image could not be loaded
				});
				// End {"load Image"} 
								
		
		});
		// End {"ready"} 

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