$(document).ready(function(){
    $("a.photogallery").fancybox({
	'transitionIn'	:	'elastic',
	'transitionOut'	:	'elastic',
	'speedIn'	:	600, 
	'speedOut'	:	200, 
	'overlayShow'	:	true
    });
});

function commentsLoad(id){    
    $.get('/comments/commentsOnContent/' + id, function(data){
	$('#comments').html(data);	
    });    
}

function addComment(id){
    $.ajax({url:"/comments/addcomment/" + id,
	    type: "POST",
	    data: "name="  + $("#name").val() + "&" +
		  "email=" + $("#email").val() + "&" +
		  "site="  + $("#site").val() + "&" +
		  "text="  + $("#text").val(),
	    success: function(data, textStatus){
		//$("#comments").html('<img src="/images/ajax-loader.gif" alt="Загрузка комментариев">'); TODO сделать контейнер для индикатора загрузчика
		if ( data.ok ){		    
		    $("#result").html("<p>Спасибо за комментарий</p>");
		    commentsLoad(id);		    
		} 
		if ( data.error ){		    
		    var output = "";
		    $.each(data.error, function(i, idata){
			output += "<li>" + idata + "</li>";
		    });
		    output = "<ul class='error'>" + output + "</ul>";		    
		    $("#result").html(output);
		}				
	   },
	   dataType: "json"});	

}
