$(document).ready(function() {

$("#show_upload_btn").css('cursor', 'pointer').click(function() {
	$("#show_upload_btn").toggle();
	$("#upload_form").toggle();
});

$("#upload_cancel_btn").css('cursor', 'pointer').click(function() {
	$("#show_upload_btn").toggle();
	$("#upload_form").toggle();
});

$("#upload_btn").css('cursor', 'pointer').click(function() {
	if ($("#member_logged_in").val()=="yes") ajaxFileUpload();
	else show_login_dialog("ajaxFileUpload");
});

});

function ajaxFileUpload() 
{
	if ($("input[name='image_file']").val() == "") return;

	$("#uploading").ajaxStart(function(){
		$("#upload_error").hide();
		$(this).show();
	}).ajaxComplete(function(){
		$(this).hide();
	});
        
	$.ajaxFileUpload({
		url:$("#coverart_upload_form").attr('action'),
		secureuri:false,
		fileElementId: "image_file",
		dataType: 'json',
		success: function(data, status) {
			if (data.error != "") {
				$("#upload_error").html(data.error);
				$("#upload_error").show();
				return;
			}
			window.location.reload();
		},
		error: function(data, status, e) {
			$("#upload_error").html(e);
			$("#upload_error").show();
		}
	});

	return false;
}  
