$(document).ready(function(){
		
		function open ()
		{
			$('a.portraitOpen').click(
				function(e) 
				{	
					e.preventDefault();
					name = $(this).attr('name');
					
					$(this).children('img').replaceWith('<li class="waiter"></li>');
					
					$.ajax
					({
						 type: "POST",
						 dataType: "text",
						 url: $(this).attr('href'),
						 success: function(data, textStatus)
						 {
							$('<img />').attr('src', '/images/photos/cookshow/' + name + '.jpg?random=' + (new Date()).getTime()).load(function(){
								$('#result').html(data);
								$('p.apercu img').replaceWith( $(this) ); 
								close() ;
							})
						 },
						 error:  function (XMLHttpRequest, textStatus, errorThrown) { }
					});
				}
			);
		}
		
		function close ()
		{
			$('a.portraitClose').click(
				function(e) 
				{	
					e.preventDefault();
					$.ajax
					({
						 type: "POST",
						 dataType: "text",
						 url: $(this).attr('href'),
						 data: '&close=close',
						 success: function(data, textStatus){ $('#result').html(data) , open() ;},
						 error:  function (XMLHttpRequest, textStatus, errorThrown) { alert('ERROR')}
					});
				}
			);
			
			$('p.apercu').click(
				function(e) 
				{	
					e.preventDefault();
					$.ajax
					({
						 type: "POST",
						 dataType: "text",
						 url: $(this).attr('href'),
						 data: '&close=close',
						 success: function(data, textStatus){ $('#result').html(data) , open() ;},
						 error:  function (XMLHttpRequest, textStatus, errorThrown) { alert('ERROR')}
					});
				}
			);
		}
		
		open();
});
