
$(document).ready(function() {  
	$("a[rel='slideshow']").colorbox({transition:"fade", photo: true});
});

function thumbsLeft() {    
	currentMarginLeft = parseFloat($('#thumbs_container').css('marginLeft')); // scroll position from the left  
	newMarginLeft = currentMarginLeft + (thumbWidth * thumbsToScroll); // calculated based on values from the page itself
	scrollSpeed = thumbsToScroll * 500; // constant rate regardless of number to scroll
	                        
	// don't scroll if there are no more the the left
	if (newMarginLeft > 0) {
		newMarginLeft = 0;
	}
		
	$("#thumbs_container").animate({ 
		marginLeft: newMarginLeft + "px"
	}, scrollSpeed );
}                        
  
function thumbsRight() {    
	currentMarginLeft = parseFloat($('#thumbs_container').css('marginLeft')); // scroll position from the left
	currentWidth = parseFloat($('#thumbs_container').css('width')); // width of all the thumbs in the container
	maskWidth = parseFloat($('#thumbs_mask').css('width')); // width of just the mask   
	newMarginLeft = currentMarginLeft - (thumbWidth * thumbsToScroll); // calculated based on values from the page itself
	scrollSpeed = thumbsToScroll * 500; // constant rate regardless of number to scroll

	// don't scroll if there are no more to the right
	if (newMarginLeft < ((currentWidth - maskWidth) * -1)) {
		newMarginLeft = ((currentWidth - maskWidth) * -1);
	}
	
	$("#thumbs_container").animate({ 
		marginLeft: newMarginLeft + "px"
	}, scrollSpeed );
}                        
  
function thumbsFirst() {   
	newMarginLeft = 0;
	$("#thumbs_container").animate({ 
		marginLeft: newMarginLeft + "px"
	}, 2000 );
}   

function thumbsLast() {
	currentWidth = parseFloat($('#thumbs_container').css('width')); // width of all the thumbs in the container
	maskWidth = parseFloat($('#thumbs_mask').css('width')); // width of just the mask   
	newMarginLeft = ((currentWidth - maskWidth) * -1); // the end
	
	$("#thumbs_container").animate({ 
		marginLeft: newMarginLeft + "px"
	}, 2000 );
}
          
function nextPhoto() {       
	if (currentPhoto == totalPhotos) {
		which = 1;
	} else {		
		which = currentPhoto + 1;
	}
	swapPhoto(which);
	checkThumbsPosition(); // verify we shouldn't scroll the thumbs 
}
  

function previousPhoto() { 
	if (currentPhoto == 1) {
		which = totalPhotos;
	} else {		
		which = currentPhoto - 1;
	}
	swapPhoto(which);  
	checkThumbsPosition(); // verify we shouldn't scroll the thumbs    
}                         

function checkThumbsPosition() {
	currentMarginLeft = parseFloat($('#thumbs_container').css('marginLeft')); // scroll position from the left
	currentWidth = parseFloat($('#thumbs_container').css('width')); // width of all the thumbs in the container
	maskWidth = parseFloat($('#thumbs_mask').css('width')); // width of just the mask
   	

    if (currentPhoto == 1) {
	  thumbsFirst();
	} else if (currentPhoto == totalPhotos) {
	  thumbsLast();  
	} else if ((currentPhoto * thumbWidth) >= ((currentMarginLeft * -1) + maskWidth)) {
		thumbsRight();
	} else if ((currentPhoto * thumbWidth) <= (currentMarginLeft * -1)) {
		thumbsLeft();
	}
}


function swapPhoto(which) {    
	if (which != currentPhoto) {
		$('#photo_' + currentPhoto).fadeOut('slow'); // fade out the old
		$('#photo_' + which).fadeIn('slow'); // fade in the new
		
		$('#thumb_' + currentPhoto).animate({  
			style: "border: 2px solid black"
		}, 'fast');
		$('#thumb_' + which).animate({
			style: "border: 2px solid white"
		}, 'fast');
		
		currentPhoto = which;
		
	}
	return false;
}     

function swapPhotoPrototype(which) {    
	if (which != currentPhoto) {
		$(currentPhoto).fade();
		$(which).appear(); 
		currentPhoto = which;
	}
	return false;
}


function nzDoNothing() {
	return false;
}
