// ***********************************************************************************
// ***********************************************************************************
// GALLERY SCRIPTS //
// ***********************************************************************************
// ***********************************************************************************	
	
	// preload images first (can run before page is fully loaded)
	$(document).ready( 
		function() {
			
			var slideTime = 400;
			
			if ( galleryid ) {
				var pageToLoad = langUrl + '/inc_gallery_zoom.php?galleryid=' + galleryid + '&supportid=0';
				
				$( "div#galleryThBoard" ).hide( 5, 
					function() {
						$( "div#galleryZoBoard" ).append('<div id="loadingPage">...loading...</div>');
						$( "div#galleryZoBoard" ).show( slideTime, 
							function() {
								$( "div#galleryZoBoard" ).empty().load( pageToLoad, 
									function() {
										$( "div#loadingPage" ).remove();
																
										// --------------------------------------
										// Tasto "chiudi"
										// --------------------------------------
										$( "div#dealersClose a" ).click(
											function () {
												$( "div#galleryZoBoard, div#dealersClose" ).hide( slideTime, 
													function () {
														$( "div#galleryZoBoard" ).empty();
														$( "div#galleryThBoard" ).show( slideTime, 
															function () {
																$( "div#galleryBoard" ).append('<div id="loadingPage">...loading...</div>');
																location.href = langUrl + '/gallery.php';
															});
															// End {"show thumb"}	
													});
													// End {"hide zoom"}	
												return false;
											});
											// End {"click close"}		
										// --------------------------------------
												
																	
										// --------------------------------------
										// Tasti "thumb"
										// --------------------------------------
										$("div#gZoomImagesCol img").hover( 
											function() {
												$( this ).animate( {opacity: "0.8"}, 10 );
											},
											function() {
												$( this ).animate( {opacity: "1"}, 10 );
											});
											// End {"hover"}
										// --------------------------------------
										
																
										// --------------------------------------
										// Click "thumb"
										// --------------------------------------
										$( "div#gZoomImagesCol a.gSupportLink" ).click(
											function () {
												
												var myZoom =  this.href;
												
												$( "div#gZoomImageBox" ).fadeOut( 200, 
													function() {
														$( "div#galleryBoard" ).append('<div id="loadingPage">...loading...</div>');
														$( "div#gZoomImageBox" ).empty().append('<IMG SRC="' + myZoom + '" ALT="" BORDER="0" CLASS="galleryZoom">');
													
														$( "div#gZoomImageBox" ).fadeIn( 200, 
															function() {
																$( "div#loadingPage" ).remove();
															});
															// End {"fadeIn"}	
													});
													// End {"fadeOut"}	
												
												return false;
											});
											// End {"click thumb"}		
										// --------------------------------------
										
															
										// --------------------------------------------------------
										// Slide Up/Down  
										// --------------------------------------------------------
										var newTop = 0;
										
										// ::: slittamento :::::::
										$( "div.slideStripeArrow a" ).click( 
											function() {						
												
												// Freccia SU 
												if ( this.id == 'arrowUp' ) {
													if ( myIdx > 1 ) {
														myIdx = myIdx - 1;
														newTop = newTop + boxSize;
														//alert(newTop +'-'+myIdx);
														var myparams = { top: "-" + ( Math.abs( newTop ) ) + "px" };	
														$("div#gZoomImagesSlide").animate(  myparams , 300 );	
													}
												}
												
												// Freccia GIU 
												if ( this.id == 'arrowDw' ) {
													if ( myIdx <= (totIdx-3) ) {
														myIdx = myIdx + 1;
														newTop = newTop - boxSize;
														//alert(newTop +'-'+myIdx);
														var myparams = { top: "-" + ( Math.abs( newTop ) ) + "px" };	
														$("div#gZoomImagesSlide").animate(  myparams , 300 );	
													}								
												}
												
												return false;
											});
											// End {"click zoom"}
										// --------------------------------------------------------
															
			
																			
									});
									// End {"load"}	
								});
								// End {"show"}	
					});
					// End {"show"}
			
			} else {
				
				var pageToLoad = langUrl + '/inc_gallery_thumbs.php';
								
				$( "div#galleryThBoard" ).append('<div id="loadingPage">...loading...</div>');
				$( "div#galleryThBoard" ).load( pageToLoad, 
					function() {
						$( "div#loadingPage" ).remove();
							
						// --------------------------------------
						// Links mouse over
						// --------------------------------------
						$("div.gListingBox img").hover( 
							function() {
								$( this ).animate( {opacity: "0.8"}, 10 );
							},
							function() {
								$( this ).animate( {opacity: "1"}, 10 );
							});
							// End {"hover"}
						// --------------------------------------
						
						
						$( "div#galleryThBoard a" ).click(
							function () {
								
								var myHref = this.href;
								
								$( "div#galleryBoard" ).append('<div id="loadingPage">...loading...</div>');
								$( "div#galleryThBoard" ).hide( 5, 
									function() {
										
										$( "div#galleryZoBoard" ).show( slideTime, 
											function() {
												$( "div#galleryZoBoard" ).empty().load( myHref, 
													function() {
														$( "div#loadingPage" ).remove();
														
														// --------------------------------------
														// Tasto "chiudi"
														// --------------------------------------
														$( "div#dealersClose a" ).click(
															function () {
																$( "div#galleryZoBoard, div#dealersClose" ).hide( slideTime, 
																	function () {
																		$( "div#galleryZoBoard" ).empty();
																		$( "div#galleryThBoard" ).fadeIn( slideTime );
																	});
																	// End {"hide zoom"}	
																return false;
															});
															// End {"click close"}		
														// --------------------------------------
														
															
														// --------------------------------------
														// Tasti "thumb"
														// --------------------------------------
														$("div#gZoomImagesCol img").hover( 
															function() {
																$( this ).animate( {opacity: "0.8"}, 10 );
															},
															function() {
																$( this ).animate( {opacity: "1"}, 10 );
															});
															// End {"hover"}
														// --------------------------------------
														
														
														// --------------------------------------
														// Click "thumb"
														// --------------------------------------
														$( "div#gZoomImagesCol a.gSupportLink" ).click(
															function () {
																
																var myZoom =  this.href;
																
																$( "div#gZoomImageBox" ).fadeOut( 200, 
																	function() {
																		$( "div#galleryBoard" ).append('<div id="loadingPage">...loading...</div>');
																		$( "div#gZoomImageBox" ).empty().append('<IMG SRC="' + myZoom + '" ALT="" BORDER="0" CLASS="galleryZoom">');
																	
																		$( "div#gZoomImageBox" ).fadeIn( 200, 
																			function() {
																				$( "div#loadingPage" ).remove();
																			});
																			// End {" ... "}	
																	
																	
																	});
																	// End {" ... "}	
																
																return false;
															});
															// End {"click thumb"}		
														// --------------------------------------
														
														
														// --------------------------------------------------------
														// Slide Up/Down  
														// --------------------------------------------------------
														var newTop = 0;
														
														// ::: slittamento :::::::
														$( "div.slideStripeArrow a" ).click( 
															function() {						
																
																// Freccia SU 
																if ( this.id == 'arrowUp' ) {
																	if ( myIdx > 1 ) {
																		myIdx = myIdx - 1;
																		newTop = newTop + boxSize;
																		//alert(newTop +'-'+myIdx);
																		var myparams = { top: "-" + ( Math.abs( newTop ) ) + "px" };	
																		$("div#gZoomImagesSlide").animate(  myparams , 300 );	
																	}
																}
																
																// Freccia GIU 
																if ( this.id == 'arrowDw' ) {
																	if ( myIdx <= (totIdx-3) ) {
																		myIdx = myIdx + 1;
																		newTop = newTop - boxSize;
																		//alert(newTop +'-'+myIdx);
																		var myparams = { top: "-" + ( Math.abs( newTop ) ) + "px" };	
																		$("div#gZoomImagesSlide").animate(  myparams , 300 );	
																	}								
																}
																
																return false;
															});
															// End {"click zoom"}
														// --------------------------------------------------------
														
														
													});
													// End {"load"}	
											});
											// End {"show"}	
									});
									// End {"hide Thumbs"}		
	
								return false;
							});
							// End {"click close"}
					});
					// End {"load"}					
			}
			
		});
		// End {"ready"}
		
		
		
// ----------------------------------------------------------------------------- 
