// ***********************************************************************************
// ***********************************************************************************
// Home 
// ***********************************************************************************
// ***********************************************************************************

$(document).ready( 
	function() {
		
		var mySlideThumb = 'none';
		$( 'div.lightImgStripe' ).animate( {opacity: "0.5"}, 1 );
		$( 'div.lightStripe' ).animate( {opacity: "0.2"}, 1 );
				
		
		// --------------------------------------------------------
		// --------------------------------------------------------
		// Thumbs RollOver 
		// --------------------------------------------------------
		// --------------------------------------------------------
		$( "div.lightGalleryBox" ).hover( 
			function() {
				var myImg = this.id + 'Thumb';
				mySlideThumb;
				$( '#' + myImg ).animate( { left: 0 }, 200 );
				// End {"hover toolbar"}	
			},
			function() {
				var myImg = this.id + 'Thumb';
				if ( myImg != mySlideThumb ) {
					$( '#' + myImg ).animate( { left: 34 }, 50 );
					// End {"animate x out"}
				}				
			});
		// End {"hover toolbar"}
		// --------------------------------------------------------
		// --------------------------------------------------------
		
		
		// --------------------------------------------------------
		// --------------------------------------------------------
		// Slide Up/Down  
		// --------------------------------------------------------
		// --------------------------------------------------------
		var newTop = 0;
		
		$( "div.slideStripeArrow a" ).click( 
			function() {						
				// Freccia PREV 
				if ( this.id == 'arrowPrev' ) {
					if ( myIdx > 1 ) {
						myIdx = myIdx - 1;
						newTop = newTop + boxSize;
						//alert(newTop +'-'+myIdx);
						var myparams = { top: "-" + ( Math.abs( newTop ) ) + "px" };	
						$("div#lightGallerySlide").animate(  myparams , 500 );	
					}
				}
				
				// Freccia NEXT 
				if ( this.id == 'arrowNext' ) {
					if ( myIdx <= (totIdx-itmXpg) ) {
						myIdx = myIdx + 1;
						newTop = newTop - boxSize;
						//alert(newTop +'-'+myIdx);
						var myparams = { top: "-" + ( Math.abs( newTop ) ) + "px" };	
						$("div#lightGallerySlide").animate(  myparams , 500 );	
					}								
				}
				
				return false;
			});
		// End {"click zoom"}
		// --------------------------------------------------------
		// --------------------------------------------------------
		
		
		
		
		// test?????????????????????????????????????????????????????????????????????????????????????????????
		// test?????????????????????????????????????????????????????????????????????????????????????????????
		var divPos = $("#lightGallery").offset();  
		var divW = $("#lightGallery").width();
		var divH = $("#lightGallery").height();
		
		$( "div#lightGallery" ).hover( 
			function( e ) {
				
				var mousePosY = e.pageY - divPos.top; 
				
				if ( mousePosY < ( Math.floor(divH/2 ) ) ) {
					if ( myIdx > 1 ) {
						myIdx = myIdx - 1;
						newTop = newTop + boxSize;
						//alert(newTop +'-'+myIdx);
						var myparams = { top: "-" + ( Math.abs( newTop ) ) + "px" };	
						$("div#lightGallerySlide").animate(  myparams , 500 );	
					}
				} else {
					if ( myIdx <= (totIdx-itmXpg) ) {
						myIdx = myIdx + 1;
						newTop = newTop - boxSize;
						//alert(newTop +'-'+myIdx);
						var myparams = { top: "-" + ( Math.abs( newTop ) ) + "px" };	
						$("div#lightGallerySlide").animate(  myparams , 500 );	
					}	
				}				
				// End {"animate x over"}
			},
			function() {
				// ...foo...
				// End {"animate x out"}
			});
		// End {"hover toolbar"}
		
		// End {"click zoom"}
		// test?????????????????????????????????????????????????????????????????????????????????????????????
		// test?????????????????????????????????????????????????????????????????????????????????????????????
		
		
		
		
		
		
		// --------------------------------------------------------
		// --------------------------------------------------------
		// Thumbs Click 
		// --------------------------------------------------------
		// --------------------------------------------------------
		$( "div.lightGalleryBoxImg a" ).click( 
			function() {
				var myUrl = this.href;
				if ( mySlideThumb != 'none' ) {
					$( '#' + mySlideThumb ).animate( { left: 34 }, 50 );
				}
				mySlideThumb = this.name;
				//alert(mySlideThumb);
				$( 'div#lightImgBoard, div#lightImgTxt' ).fadeOut( 200, 
					function () {
						$( 'div#lightCntImg' ).empty().append( '<div id="loadingImage">...loading...</div>' );
						$( 'div#lightCntImg' ).load( myUrl, 
							function () {
								$( 'div#loadingImage' ).remove();
								$( 'div#lightImgBoard, div#lightImgTxt' ).fadeIn( 200 );								
							});
						// End { "load" }
					});
				// End { "fadeOut" }
				
				
				return (false);
			});
		// End {"click"}
		// --------------------------------------------------------
		// --------------------------------------------------------
		
		
		
		// --------------------------------------------------------
		// --------------------------------------------------------
		// Prima immagine default 
		// --------------------------------------------------------
		// --------------------------------------------------------
		$( "div.lightGalleryBoxImg a" ).each( 
			function ( i ) {
				if ( i == 0 ) {
					var myFirstUrl = this.href;
										
					if ( myFirstUrl != undefined ) {
						$( 'div#lightImgBoard, div#lightImgTxt' ).fadeOut( 200, 
							function () {
								$( 'div#lightCntImg' ).empty().append( '<div id="loadingImage">...loading...</div>' );
								$( 'div#lightCntImg' ).load( myFirstUrl, 
									function () {
										$( 'div#loadingImage' ).remove();
										$( 'div#lightImgBoard, div#lightImgTxt' ).fadeIn( 200 );								
									});
								// End { "load" }
							});
						// End { "fadeOut" }
					}
				}
			});
		// End { "each" }
		// --------------------------------------------------------
		// --------------------------------------------------------
		
		
		
										
	});
	// End {"ready"}
	
// ***********************************************************************************
// ***********************************************************************************
