// ***************************************************************************** 
// *****************************************************************************
// SCHEDA PRODOTTO
// Deve assere dichiarato: 'imgs_array'
// ***************************************************************************** 
// *****************************************************************************
 
$(document).ready( 
	function() {
		
		// ---------------------------------------------------------------- 
		// ---------------------------------------------------------------- 
		// IMAGE GALLERY
		// ---------------------------------------------------------------- 
		// ---------------------------------------------------------------- 
		$( "#imgPrev, #imgNext" ).fadeIn( 10, 
			function() {
				
				// Next --------------------
				$( "#imgNext a" ).click(
					function() {
						
						if ( p < (totImages-1) ) {
							p_next = p + 1;
						} else {
							p_next = 0;
						} 
						//alert( p_next );
								
						$( "img#medImage" ).fadeOut( 100, 
							function() {
								$( "img#medImage" ).remove();
								$( "div#detailsImageMask" ).prepend( '<IMG SRC="' + imgs_array[ p_next ] + '" BORDER="0" ID="medImage" CLASS="imgDetails">' );
								$( "img#medImage" ).fadeIn( 100, 
									function() {
										p = p_next;
										//alert( p );
									}); 
							});
							// End {"fadeOut"} 
							
						return false;
					});
				// End {"click Next"} 
				// --------------------------
				
				// Prev --------------------
				$( "#imgPrev a" ).click(
					function() {
						
						if ( p > 0 ) {
							p_prev = p - 1;
						} else {
							p_prev = (totImages-1);
						} 
						//alert(imgs_array[ p_prev ]);
						
						$( "img#medImage" ).fadeOut( 100, 
							function() {
								$( "img#medImage" ).remove();
								$( "div#detailsImageMask" ).prepend( '<IMG SRC="' + imgs_array[ p_prev ] + '" BORDER="0" ID="medImage" CLASS="imgDetails">' );
								$( "img#medImage" ).fadeIn( 100 , 
									function() {
										p = p_prev;
										//alert( p );
									}); 
							});
							// End {"fadeOut"} 
							
						return false;
					});
				// End {"click Prev"} 
				// --------------------------
				
				//newImage = imgs_array[ p ];
	
			});
		// End {"fadeIn"} 
		// ---------------------------------------------------------------- 
		// ---------------------------------------------------------------- 
			
			
			
			
		// ================================================================ 
		// ================================================================ 
		// NEWS UTILITIES
		// ================================================================ 
		// ================================================================ 
		
		var slideTime = 600;
		
		// --------------------------------------------------------
		// VIDEO 
		// --------------------------------------------------------
		$( 'div#overlay' ).animate( {opacity: "0.8"}, 1 );
				
		$( "a.video_link, a.group" ).click(
			function () {
					
				var popup_href = this.href;
				
				$( "div#overlay" ).fadeIn( slideTime, 
					function () {
						$( "div#productGallery" ).fadeIn( slideTime, 
							function () {
							
								// ::: Lettura popup video ::: 
								$( "div#galleryBoardImg" ).append('<div id="loadingImage">...loading...</div>');
								
								var myProperties = { width: popup_w, height: popup_h };
											
								$( "div#galleryBoardImg" ).load( popup_href, 
									function () {
										$( "div#galleryBoardImg-inner" ).animate( myProperties, 500, 
											function () {
												$( "div#loadingImage" ).remove();
												
												//alert(popup_href);
											});
										// End {"animate popup"}	
									});
								// End {"load popup"}	
								// ::: // Lettura popup video ::: 		
										
								// ::: Tasto "chiudi" :::
								$( "div#productGallery a.close" ).click(
									function () {
										$( "div#productGallery" ).fadeOut( slideTime, 
											function () {
												$( "div#overlay" ).fadeOut( slideTime,
													function () {
														$( "div#galleryArrowsImg" ).empty();
													});
												// End {"fadeOut overlay"}	
											});
										// End {"fadeOut productGallery"}	
									});
								// End {"click close"}		
								// ::: // Tasto "chiudi" :::
								

							});
						// End {"fadeIn productGallery"}
					});
				// End {"fadeIn overlay"}	
				
				return (false);
	
			});
		// End {"click video"}	
		// --------------------------------------------------------
		
		
		// --------------------------------------------------------
		// SEND TO FRIEND 
		// --------------------------------------------------------
		$('div#pageUtilities a#utilitySendToFriend').click( 
			function() {
								
				var myLoad = this.href;
				
				$( "div#overlay" ).fadeIn( slideTime, 
					function () {
						$( "div#sendToFriend" ).fadeIn( slideTime, 
							function () {
																			
								$( "div#sendToFriendBoard" ).load( myLoad, 
									function () {
												
										// ::: Tasto "chiudi" :::
										$( "div#sendToFriend a.close" ).click(
											function () {
												$( "div#sendToFriend" ).fadeOut( slideTime, 
													function () {
														$( "div#overlay" ).fadeOut( slideTime,
															function () {
																$( "div#sendToFriendBoard" ).empty();
															});
														// End {"fadeOut overlay"}	
													});
												// End {"fadeOut productGallery"}	
											});
										// End {"click close"}			
										// ::: // Tasto "chiudi" :::
										
										
										// ::: Submit Form :::
										$( "a#formSubmit" ).click(
											function(){
											
												if ( SendToFriend_Validator( document.sendToFriendForm ) ) {
																
													$.ajax({
														url: "inc_sendToFriend.php",
														type: "POST", 
														scriptCharset: "iso-8859-1", 
														//scriptCharset: "iso-8859-1", 
														data:  $("#sendToFriendForm").serialize(),
														contentType: "application/x-www-form-urlencoded;charset=ISO-8859-1",
														dataType: "html",
														success:
															function( html ){
																
																$("div#sendToFriendBoard").empty().append( html ).show( 100, 
																	function(){
																		
																		// --------------------------------------
																		// Tasto "chiudi"
																		// --------------------------------------
																		$( "div#sendToFriend a.close" ).click(
																			function () {
																				$( "div#sendToFriend" ).fadeOut( slideTime, 
																					function () {
																						$( "div#overlay" ).fadeOut( slideTime,
																							function () {
																								$( "div#sendToFriendBoard" ).empty();
																							});
																						// End {"fadeOut overlay"}	
																					});
																				// End {"fadeOut productGallery"}	
																			});
																		// End {"click close"}			
																		// --------------------------------------
																			
																	});
																// End {"Hide Attendere"}
															}
															// End {"Ajax success send"}
													});
													// End {"Ajax"}
												
												}

												return (false);
													
											});
										// End {"Click"}
										// ::: // Submit Form :::
															
									});
								// End {"load"}
							});
						// End {"load"}
					});
				// End {"fadeIn overlay"}
				
				return (false);

			});
		// End {"click send to friend"}
		// --------------------------------------------------------
		
		
		// --------------------------------------------------------
		// PRINT PAGE 
		// --------------------------------------------------------
		$('div#pageUtilities a#utilityPrint').click( 
			function() {
				window.open( this.href, 'printpage', 'toolbars=1, scrollbars=1, location=1, statusbars=0, menubars=1, resizable=1, width=800, height=600' ); 
				return (false);
			});
		// End {"click"} 
		// --------------------------------------------------------
		
		// ================================================================ 
		// ================================================================ 
		
		
			
	});
// End {"ready"} 

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



// --------------------------------------------------- 	
// CHECK SEND TO FRIEND FORM  	
// --------------------------------------------------- 	
	function SendToFriend_Validator( theForm ) {	
		// Nome
		if ( theForm.elements[ 'new_name' ].value == "" ) {
			
			$( "div#formSearchCeck" ).fadeIn( 100, 
				function(){
					$( "div#formSearchCeck" ).empty().append( 'Nome mancante.' ).fadeIn( 100, 
						function(){
							theForm.elements[ 'new_name' ].focus();
							
							$( "div#dealersSearchCech a.close" ).click(
								function(){
									$( "div#formSearchCeck" ).empty().fadeOut( 100 );
								});
							// End {"click close"}
						});
					// End {"fadeIn MSG"}
				});
			// End {"fadeIn Slert box"}
			return (false);
		}
		// Nome //			
		
		// E-mail
		if ( ( !( theForm.elements[ 'new_email' ].value.search(/^\w+((\+\w+)|(-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.([A-Za-z0-9])([A-Za-z0-9]?)([A-Za-z0-9]?)$/)!= -1)) || ( theForm.elements[ 'new_email' ].value == "" ) ) {  
			
			$( "div#formSearchCeck" ).fadeIn( 100, 
				function(){
					$( "div#formSearchCeck" ).empty().append( 'E-mail non valida o mancante.' ).fadeIn( 100, 
						function(){
							theForm.elements[ 'new_email' ].focus();
							
							$( "div#dealersSearchCech a.close" ).click(
								function(){
									$( "div#formSearchCeck" ).empty().fadeOut( 100 );
								});
							// End {"click close"}
						});
					// End {"fadeIn MSG"}
				});
			// End {"fadeIn Slert box"}
			return (false);
		}
		// E-mail //		
		
		
		// E-mail Amico
		if ( ( !( theForm.elements[ 'new_friend_email' ].value.search(/^\w+((\+\w+)|(-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.([A-Za-z0-9])([A-Za-z0-9]?)([A-Za-z0-9]?)$/)!= -1)) || ( theForm.elements[ 'new_friend_email' ].value == "" ) ) {  
			
			$( "div#formSearchCeck" ).fadeIn( 100, 
				function(){
					$( "div#formSearchCeck" ).empty().append( 'E-mail non valida o mancante.' ).fadeIn( 100, 
						function(){
							theForm.elements[ 'new_friend_email' ].focus();
							
							$( "div#dealersSearchCech a.close" ).click(
								function(){
									$( "div#formSearchCeck" ).empty().fadeOut( 100 );
								});
							// End {"click close"}
						});
					// End {"fadeIn MSG"}
				});
			// End {"fadeIn Slert box"}
			return (false);
		}
		// E-mail Amico //			
		
		
		// Messaggio
		if ( theForm.elements[ 'description' ].value == "" ) {
			
			$( "div#formSearchCeck" ).fadeIn( 100, 
				function(){
					$( "div#formSearchCeck" ).empty().append( 'Messaggio mancante.' ).fadeIn( 100, 
						function(){
							theForm.elements[ 'description' ].focus();
							
							$( "div#dealersSearchCech a.close" ).click(
								function(){
									$( "div#formSearchCeck" ).empty().fadeOut( 100 );
								});
							// End {"click close"}
						});
					// End {"fadeIn MSG"}
				});
			// End {"fadeIn Slert box"}
			return (false);
		}
		// Messaggio //					
			
		
		
		
		theForm.okForm.value = true;
		return (true);
	}
// ***************************************************************************** 
// ***************************************************************************** 

