
var blog_proc = "/_front_end/go.php?what=blog&";

$(document).ready(function(e){
	
	$("a.ch_blog_rec_status").bind("click", change_status);
	$("a.delete_blog_rec").bind("click", delete_record);

	$("div.blog_rec_content a").each(
	    function()
	    {
	       var img = $(this).find("img");
	       if(img.attr('src') != undefined){
	    		var reg=/thumb/g;
	    		var url=img.attr("src").replace(reg, "original")
	           $(this).attr('href',url);
	           $(this).attr('rel',"facebox");
	       }
	    }
	);
	 
	$('a[rel*=facebox]').facebox();

});

var change_status = function(e){
	 
	var blog_obj = $(this).parent().parent();
	var the_href = $(this);
	var rec_id = blog_obj.attr("rec_id");
	 
	$.ajax({
		type: "GET",
		url: blog_proc+"action=active&rec_id="+rec_id+"&status="+$(this).attr("status"),
		success: function(xml){
			if($("message", xml).attr("result")>0){
				blog_obj.attr("class", $("message", xml).attr("status")==1?"active_blog_rec":"unactive_blog_rec");
				the_href.attr("status", $("message", xml).attr("status"));
				the_href.text($("message", xml).attr("link_text"));
			}
		}
	});
	
	return false;
};

var delete_record = function(e){
	 
	if(confirm("Вы действительно хотите удалить запись?")){
		
		var blog_obj = $(this).parent().parent();
		var rec_id = blog_obj.attr("rec_id");

		$.ajax({
			type: "GET",
			url: blog_proc+"action=delete&rec_id="+rec_id,
			success: function(xml){
				if($("message", xml).attr("result")>0){
					blog_obj.remove();
				}
			}
		});

	}
	
	return false;
	
}