jQuery(document).ready(function(){							
	
	jQuery.preload( 'a.gallerythumb',{
		onFinish:function(data){														
			//alert(data.total);
		}
	});
		
	function updatePhoto(objEvent,photoType){
		var href = objEvent.href;
		var title = objEvent.title;
		var image_id = objEvent.id
		image_id = image_id.substr(6,image_id.length);
		
		var main_image = href.substr(0,href.indexOf('mid_')) + href.substr(href.indexOf('mid_')+4,href.length);
		var main_image_only = href.substr(href.indexOf('mid_')+4,href.length);
	

	
		jQuery('#GalleryPic')
			.fadeOut(600,function(){
				
				jQuery('#photo_title').text('');
				jQuery('#photo_caption').html('');
				
				jQuery('#galleryimg')
					.attr('src',href)
					.attr('alt',title);
					
					jQuery.post('/ajax/gallery1',{'ID-Photo' : image_id,'PType':photoType},function(data,textStatus){																								
						jQuery('#photo_title').text(data.PhotoTitle);
						jQuery('#photo_caption').html(data.PhotoText);
						jQuery('#GalleryPic').fadeIn(600);
					},'json');										 				 						
			}) //end fade out
			.parent().get(0).href = main_image;
			return false;	
	}
		
	jQuery('.gallerythumbSubPages').click(function(){										   			
		return updatePhoto(this,'2');
	});//end .gallerythumb click
	
	jQuery('.gallerythumbPages').click(function(){										   			
		return updatePhoto(this,'1');
		
	});//end .gallerythumb click
	
	jQuery('.gallerythumbSubSubPages').click(function(){										   			
		return updatePhoto(this,'3');
		
	});//end .gallerythumb click	
	
	jQuery(document).ajaxError(function(event, XMLHttpRequest, ajaxOptions, thrownError){					 
	 	//alert (XMLHttpRequest.responseText);
	 });    

});
