

function ShowThumb( strDirection ){
	var objThumbFrame = $( "#thumbframe" );
	var objThumbStrip = $( "#thumbstrip" );
	var intLeft = 0;
	var intRightWidth = 0;
	var intLeftWidth = 0;
	var intTargetLeft = 0;
	var objPhotos = null;
	var intTotalWidth = 0;
	var arrBuckets = new Array( { offset: 0, left: 0, width: 0, index: 0 } );
	var objBucket = arrBuckets[ 0 ];
	var intBucketIndex = 0;
	var arrPhotoOffsets = new Array();
	var intThumbWidth = 0;
	
	
	// Check to see if we have our objects.
	if (objThumbFrame[ 0 ] && objThumbStrip[ 0 ]){
	
		// Get all the photos in the photo strip.
		objPhotos = $( objThumbStrip ).children( "a" );
		
		
		// Iterate over the photos to get the total width of the elements.
		objPhotos.each(
			function( intPhotoIndex ){
				
				// Get the width of the current thumb.
				intThumbWidth = (
					$( this ).width() +		// Width of the image.
					4						// Width of right border.
					);
				
				// Get the total width at this point.
				intTotalWidth = (intTotalWidth + intThumbWidth);
					
					
				// Check to see if the bucket width is bigger than the current 
				// photo frame width if we add the current thumb to the bucket.
				if ((objBucket.width + intThumbWidth) > objThumbFrame.width()){
						
					// Create a new bucket.
					arrBuckets[ arrBuckets.length ] = { 
						offset: intPhotoIndex, 
						left: (objBucket.left - objBucket.width), 
						width: intThumbWidth,
						index: arrBuckets.length
						};
					
					// Get the new bucket.
					objBucket = arrBuckets[ arrBuckets.length - 1 ];
				
				} else {
					
					// Add the current width to the current bucket.
					objBucket.width += intThumbWidth;
					
				}
				
				
				// Check to see if our photo is current in this bucket.
				if (objThumbFrame.attr( "photooffset" ) == intPhotoIndex){
				
					// Get the index of the current bucket.
					intBucketIndex = objBucket.index;
				
				}
					
			}
			);
			
			
		if (arrBuckets.length > 1){
			
			if (objBucket.width < objThumbFrame.width()){
			
				objBucket.left += (objThumbFrame.width() - objBucket.width + 4);
			
			}
			
		}
			
		
		// ASSERT: At this point, we have all the bucket information set up.
		// This contains the photo offset of each bucket, it's overall width
		// and the left px value of the bucket (relative to parent).
		
		
		// Set the bucket object to null. We will use this variable to hold
		// the target bucket going forward.
		objBucket = null;
		
		
		// Check to see which direction we are going in.
		switch (strDirection){
		
			case "next":
			
				// Check to see if we have a bucket to move to.
				if (intBucketIndex < arrBuckets.length){
				
					// Get the next buckets.
					objBucket = arrBuckets[ intBucketIndex + 1 ];
				
				}
			
				break;
				
				
			case "prev":
				
				// Check to see if we have a bucket to move to.
				if (intBucketIndex > 0){
				
					// Get the previous buckets.
					objBucket = arrBuckets[ intBucketIndex - 1 ];
				
				}
				
				break;
				
				
			default:
				// Get current bucket.
				objBucket = arrBuckets[ intBucketIndex ];
				break;
		
		}
		
		
		// Check to see if we have a target bucket.
		if (objBucket){
		
			// Set the target left of the given bucket.
			objThumbFrame.attr( "targetleft", objBucket.left );
			
			// Set the target photo offset.
			objThumbFrame.attr( "photooffset", objBucket.offset );
			
			
			objThumbStrip.animate(
				{ left: objBucket.left },
				"slow",
				jQuery.easing.expoinout
				);
				
				
			// Check to see if we have to change the prev button.
			if( objBucket.index == 0 ){
			
				// Turn off previous thumb button.
				$( "#prevthumb" ).attr( "class", "prevdisabled" );
			
			} else {
				
				// Turn on previous thumb button.
				$( "#prevthumb" ).attr( "class", "prev" );
				
			}
			
			
			// Check to see if we have to change the next button.
			if( objBucket.index == (arrBuckets.length - 1)){
			
				// Turn off next thumb button.
				$( "#nextthumb" ).attr( "class", "nextdisabled" );
			
			} else {
				
				// Turn on next thumb button.
				$( "#nextthumb" ).attr( "class", "next" );
				
			}
			
		}
		
	}
	
	
	
	// Return out.
	return;
}


function ShowPhoto( objSource, strPath ){
	var objPhotoFrame = $( "#photoframe" );
	var objPhoto = null;
	
	// Make sure we have our photo frame.
	if (objPhotoFrame){
		
		// Get the photo image object.
		objPhoto = $( objPhotoFrame.children( "img" )[ 0 ] );
		
		
		// Make sure we found our photo.
		if (objPhoto.length){
		
			
			
			
			
		
		
			// Get the previous thumb that was on.
			$( objSource.parentNode ).children( ".on" ).attr( "class", "off" );
			
			// Turn this one on.
			objSource.className = "on";
		
			objPhoto.fadeOut(
				"fast",
				function(){		
					
					// Set photo source.
					objPhoto.attr( "src", strPath );
					
					// Show photo.
					ShowPhotoDo( objSource, objPhoto );
				}
				);
				
		}
			
	}
}


function ShowPhotoDo( objSource, objPhoto ){
	var objImage = new Image();
	var objPrevThumb = null;
	
	// Set the source image to this one.
	objImage.src = objPhoto.attr( "src" );
	
	// Check to see if the photo is complite.
	if (objImage.complete != false){
	
		// Fade in main photo.
		objPhoto.fadeIn( "normal" );
	
	} else {
		
		// Call this function again.
		setTimeout(
			function(){
				ShowPhotoDo( objSource, objPhoto );
			},
			100
			);
				
	}
}