var the_target = null;
var post_article_id = null;

function post(target, article_id) {
	the_target = target;
	post_article_id = article_id;
	jQuery("#post_dialog").empty().dialog('open');
	jQuery("#post_dialog").load("/copy?article_id="+article_id+"&portlet=1&dialog=1 #postmainbody",post_init);

}

function post_init() {
	init_tags();

	jQuery("#tag-editing").tagedit({
		"initial_libraries":[GLOBAL.username],
		"all_tags": GLOBAL.all_tags
	});

	jQuery("#libraries input").change(function() {
		var libraries = [];
		jQuery("#libraries input:checked").each(function(){
			var e = jQuery(this);
			//alert(e.data("library"));
			libraries.push(e.data("library"));
		});
		jQuery("#tag-editing").tagedit("setTags",libraries);
	});

	jQuery("#tags-dummy").remove();

}

// this "overrides" the dummy function in post_known.adp.
function do_post() {
	if (!post_article_id) {
		return false;
	}
	var data = jQuery("#frm").serializeArray();
	data["callback"]="?";
	data["article_id"]=post_article_id;
	jQuery.post("/do_post_known_ajax", data, function(x) {}, "jsonp" );
	jQuery("#post_dialog").dialog('close');

	jQuery(the_target).closest("tr").remove();

	showTopRecs();

	var c = jQuery("#recs_list_table tr").length;
	if (c==1) {
		jQuery("#article_count").text("1 recommendation");
	} else {
		jQuery("#article_count").text(c+" recommendations");
	}
	if (c <= max_items) {
		jQuery("#top_only").hide();
	}
	post_article_id = null;

	return false;
}


jQuery(function(){
	jQuery("#post_dialog").dialog({
		bgiframe: true,
		autoOpen: false,
		modal: true,
		width: "960px",
		position: ["middle", "top"],
		resizable: false,
		draggable: false,
		minHeight: 0
	});
});



