/**
 * Info
 * @uses Ajax
 * @version 1.0.2
 */
Loader.scripts(["ajax"], "info_init");

function info_init()
{
	$("#favourite,#subscribe,#subscribe_comment").bind("click", info_subscribe);
	$("#votes_link").click(info_votes);

	var download_button = new Image();
	download_button.src = "/img/download_big_hover.png";
}

function info_subscribe()
{
	if (!auth_request_auth())
		return;

	var span = $(this);

	var pid = $("#program_id").val();
	var section = $("#section").val();
	if (pid == "")
		return;

	var type;
	if (span.hasClass("active"))
		type = "delete";
	else
		type = "add";

	var what = span.attr("id");
	if (what == "subscribe_comment")
		what = "comment";

	var result = Ajax.post("/subscriptions/toggle_ajax/", {'type': type, 'what': what, 'pid': pid, 'section': section});

	var success = result.find("success");
	if (!success.length)
		return;

	span.toggleClass("active");
}

function info_votes()
{
	if (!auth_request_auth())
		return false;

	var pid = $("#program_id").val();
	if (pid == "")
		return false;

	Ajax.post("/votes_ajax/", {'pid': pid});

	$("#votes_link").remove();
	$("#votes_success").show();
	return false;
}

$(info_init);
