$(function() {

	$("a#comix_image").fancybox(); 


	//vote posts & comments
	$("a[rev='vote-on'], a[rev='vote-against']").click( function() {
		var mark = $(this).attr("title") == "+"? 1:-1;
		var item_id =  $(this).attr("value");
		var href = $(this);
		var is_comment = $(this).hasClass('comm');
		
		$.ajax({
			   type: "POST",
			   url: $(this).hasClass('comm')? '/comment/vote': '/post/vote',
			   data: ( is_comment? {comment_id : item_id, mark:mark}: {post_id : item_id, mark:mark} ),
			   dataType: "json",
			   success: function(msg){

			    if(msg['result'] == 1) //success
			    {
                    var el = href.parent();
                    el.children("span").empty().append(msg["rating"]);
					if (mark=='-1')
					{ 
						$(href).attr("class",'voted-against');
						$(href).parent().find("a[rev='vote-on']").attr("class",'vote-on');
						if (is_comment) {
							$(href).parent().find("a[rev='vote-on']").addClass('comm');
							$(href).addClass('comm');
						}
					}
					else if (mark=='1')
					{ 
						$(href).attr("class",'voted-on');
						$(href).parent().find("a[rev='vote-against']").attr("class",'vote-against');
						if (is_comment) {
							$(href).parent().find("a[rev='vote-against']").addClass('comm');
							$(href).addClass('comm');
						}
					}
                    //alert(el);
			    }
			    if(msg['result'] == 2) //validation error
			    {
			    	alert("validation error");
			    }
			 },
			    error: function(msg){
			    	 alert("Error: you must be logged in "); }
          });
		      return false;
	});
	
	//show only new comments
	$("a[show='new']").click( function() {	
	$("div[time='old']").hide();
	return false;
	});
	
	$("input[rel='sticky']").blur(function(){
	$.post('/post/adm_sticky', { id:$(this).attr('rev'),value:$(this).val() },function(data) { var foo='bar'; });
//	alert('sticky');
	});
	
	$("a[show='all']").click( function() {	
	$("div[time='old']").show();
	return false;
	});
});


function confirm_delete_post()
{
	if(confirm("Точно удалить?"))
		return true;
	else
		return false;
}