
function ajaxFileUpload() {
		var upload_success = false;

		jQuery("#loading")
		.ajaxStart(function(){
			jQuery(this).show();
		})
		.ajaxComplete(function(){
			jQuery(this).hide();
		});

		jQuery.ajaxFileUpload
		(
			{
				url:'http://borealopportunity.ca/getinvolved/wp-content/plugins/comment-image-uploader/scripts/doajaxfileupload.php',
				secureuri:false,
				fileElementId:'fileToUpload',
				dataType: 'json',
				success: function (data, status)
				{
					if(typeof(data.error) != 'undefined')
					{
						if(data.error != '')
						{
							alert(data.error);
						}else
						{
							var item_link = data.file + '<!-- <a href="#" onclick="return add_img_to_comment(\'' + data.file + '\')">(Insert)</a>-->';

							jQuery("#uploaded_files").html( jQuery("#uploaded_files").html() + "<ul><li>" + item_link + "</li></ul>");

							jQuery("#fileToUpload").val('');

							add_img_to_comment(data.file);

						}
					}
				},
				error: function (data, status, e)
				{
					alert('Error: ' + e);
				}
			}
		)

		return false;

	}

function add_img_to_comment(img) {
	jQuery("#uploaded_comment_files").val( jQuery("#uploaded_comment_files").val() + "[img]" + img + "[/img]");
	return false;
}

/* added after the fact to upload image upon "Submit Comment" */
function upload_on_submit() {
	if ( jQuery('#fileToUpload').val() != '' ) {
		ajaxFileUpload();
		jQuery('#fileToUpload').bind("change", function(){ upload_on_submit(); });
	}
}

jQuery(document).ready(function() {
	jQuery('a[@rel*=lightbox]').lightBox();
	jQuery('#fileToUpload').change(function () {
		upload_on_submit();
	});
});
