function setMainPhoto(photoNumber){
	var fade_time = 2000;
	current_photo = photoNumber;
	
	//We load the image in an invisible div so it's cached already...
	jQuery('#pre_cache_img').attr('src', photos[current_photo].thumbnailerPath);
	jQuery('#main_photo_img').animate({ opacity: 0 }, fade_time / 2);
	setTimeout(
			function(){				
				jQuery('#main_photo_img').attr('src', photos[current_photo].thumbnailerPath);
				jQuery('#main_photo_img').animate({ opacity: 1 }, fade_time / 2);
			}, fade_time / 2
	);	
}

function zoomMainPhoto(){
	showPhotoInThickBox(current_photo);
}

function showPhotoInThickBox(photoNumber){
	//To get Thickbox to automatically find the photo in the list of photos...  we need a full url...
	//So we grab it from the a tag instead of the photo object.
	//jQuery('#temp_a').attr('href', photos[photoNumber].path);
	
	tb_show(photos[photoNumber].desc, jQuery('.photoThumb')[photoNumber].href, 'AdPhotos');
}

var current_photo_row = 1;

function photos_init(){
	updatePhotoUI();
}

function updatePhotoUI(){
	var photo_height = jQuery('.photo-frame').height();
	jQuery('#photo_table').animate({ top: -photo_height * current_photo_row + photo_height }, 600);
	
	if(current_photo_row == 1){
		jQuery('#photos_back').hide();
		
	}
	else{
		jQuery('#photos_back').show();	
	}
	
	if(photos.length > current_photo_row * 4 + 4){
		jQuery('#photos_more').show();
	}	
	else{
		jQuery('#photos_more').hide();
	}
}

/*
function showOrHidePhotoFrame(){
	if(isRowVisible(this)){
		jQuery('#' + this.id).show();
	}
	else{
		jQuery('#' + this.id).hide();
	}	
}
*/


function isRowVisible(photo_frame){
	if(photo_frame.id == "photo-frame-" + current_photo_row || 
		 photo_frame.id == "photo-frame-" + (current_photo_row + 1)){
		return true;
	}
	return false;
}

function photos_more(){
	if(hasMore()){	
		current_photo_row++;
		updatePhotoUI();
	}
}

function photos_back(){
	if(hasLess()){
		current_photo_row--;
		updatePhotoUI();
	}
}

function photos_enlarge(){
	zoomMainPhoto();
}

function hasMore(){
	if(photos.length > current_photo_row * 4 + 4) return true;
	return false;
}

function hasLess(){
	if(current_photo_row > 1) return true;
	return false;
}