$(document).ready(function(){
/*	var _maxHeight =400;
	$('ul.gallery').children('li').each(function(i) {
		if($(this).height() > _maxHeight){
			_maxHeight = $(this).height();
		}
	});
*/
	//$('ul.gallery li:first-child').addClass('active');
	$("#menu-list li ul li a").click(function(){
		clickedGallery = $(this).parent().parent().parent().children('a.menu').attr('href');

		clickedImage = $(this).attr('href');
		
		if(clickedGallery != currentGallery){
			currentGallery = clickedGallery;
			$('#content').load(clickedGallery, function(){  		
				myGallery = $('ul.gallery').galleria({
				history   : false, // activates the history object for bookmarking, back-button etc.
				clickNext : true, // helper for making the image clickable
				onImage   : function(image,caption,thumb,caption_text) { // let's add some image effects for demonstration purposes
			
						// fade in the image & caption

						if(!$.browser.msie){
							image.css('display','none');
							caption.css('display','none');
							caption_text.css('display','none');
							// add a title for the clickable image
						}
				
						image.attr('title','Next image >>');

						image.load(function(){
							var marginTop = $('.galleria_container').height() - $(this).height() -$('.caption').height()-$('.caption_text').height() -15;
							$('img.replaced').css('margin-top', marginTop+'px');
							$('img.replaced').fadeIn(450);
							$('.caption').fadeIn(750);
							$('.caption_text').fadeIn(1000);
						});

						_src = image.attr('src');
						_currentGallery = _src.replace(/\/images\/([^\/]+)\/([^\/]+)\/.*$/, '$1/$2');
						$('.selectedItem').removeClass('selectedItem');
						$('li a[href*="/images/'+_currentGallery+'/"]').addClass('selectedItem');
//						_currentMenu = _currentGallery.replace(/([^\/]+)\/.*$/, '$1');

							
					}
				}); 
				
				myGallery.galleria.onPageLoad(clickedImage);	
				$('#content').append('<p class="nav foo"><a href="#" onclick="$.galleria.prev(); return false;">&laquo; previous</a> | <a href="#" onclick="$.galleria.next(); return false;">next &raquo;</a></p>');
				$('.nav').fadeIn(100);	

			});
		}
		else{
			myGallery.galleria.onPageLoad(clickedImage);	
		}

	return false;
	});
	
	$("a.page").click(function(){
		$('#content').load($(this).attr('href'), function(){
			scrambled = $('#contact_moi').attr('rel');
			if(scrambled){
				$('#contact_moi').attr('href', 'mailto:'+$.rotate13(scrambled)).text(
			        $.rotate13(scrambled));
			}
		});
		
		$("#menu-list").accordion({
			header:"a.menu",
			active:"",
			autoHeight: false
		});
		return false;
	});
	
});
currentGallery = '';


