$(function(){
	$('.view_photo').click(function(){
		var elem = $(this);

		var a = elem.parent().find('a.gallery');
		if(a.length==0)
		{
			$.ajax({
				url: elem.attr('href'),
				type: "POST",
				data: '1=1',
				dataType : "json",
				beforeSend: function(XMLHttpRequest){
					elem.hide().after($('<span class="ajax_loader" >&nbsp;&nbsp;&nbsp;&nbsp;</span>'));
				},
				success: function(data, textStatus, XMLHttpRequest){
					elem.show().next('.ajax_loader').remove();

					for (i in data.result)
					{
						var a = $(data.result[i]);
						a.hide();
						elem.after(a);
					}	

          elem.parent().find('a.gallery').slimbox({
            counterText: 'Фото {x} из {y}',
            loop: true
          });
          
					/*
          elem.parent().find('a.gallery').lightBox({
            imageLoading:			'/public/js/jquery-lightbox/images/lightbox-ico-loading.gif',		// (string) Path and the name of the loading icon
            imageBtnPrev:			'/public/js/jquery-lightbox/images/lightbox-btn-prev.gif',			// (string) Path and the name of the prev button image
            imageBtnNext:			'/public/js/jquery-lightbox/images/lightbox-btn-next.gif',			// (string) Path and the name of the next button image
            imageBtnClose:		'/public/js/jquery-lightbox/images/lightbox-btn-close.gif',		// (string) Path and the name of the close btn
            imageBlank:				'/public/js/jquery-lightbox/images/lightbox-blank.gif',			// (string) Path and the name of a blank image (one pixel)          
						overlayOpacity:0.5,
						fixedNavigation: true,
						txtImage: "Фото",
						txtOf: "из"  
					});					
          */
          
					a.trigger('click');
				},
				error: function(XMLHttpRequest, textStatus, errorThrown){
					elem.next('.ajax_loader').remove();
				}
			});
		}
		else
		{
			a.trigger('click');
		}
		return false;
	});	
});

